I've been looking through a lot of tutorials on jQuery draggable and trying to apply it to ASP.NET MVC, but I am really confused.
Does anyone know of some simpler samples.
#model locat.Models.LoginModel
#{
ViewBag.Title = "Log in";
}
#using (Html.BeginForm(null, null, FormMethod.Post, new { id = "msform" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary()
<!-- fieldsets -->
<div id="drag">
<fieldset>
<h2 class="fs-title">Login</h2>
<h3 class="fs-subtitle"></h3>
<input name="UserName" type="text" placeholder="Username">
<input name="Password" type="Password" placeholder="Password">
<input type="button" name="next" class="next action-button" value="New User" />
<input type="submit" name="next" class="nexts action-login" value="Log in" />
</fieldset>
</div>
}
<script>
$(function () {
$("#drag").draggable();
});
</script>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
#Scripts.Render("~/bundles/jqueryui")
}
You have one of these problems :-
Your jQuery or jQuery UI Javascript path files are wrong.
Your jQuery UI does not include draggable.
Your div is unstyled or empty, therefore there is nothing to drag.
Something is colliding with your jQuery or jQuery UI so it doesn't
work.
In your question ur div with id="drag" in not styled so give style to it so that draggable will work on it.
ut your dragable elements inside Ul as below and don't forget to include Jquery UI files reference:
<ul id="sortable">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ul>
AND Jquery:
$(function() {
$( "#sortable" ).draggable({
});
});
Working Demo Is Here http://jsfiddle.net/booyaa/YvJhE/
Related
I thought I knew jq selectors but this is killing me. Given this html snippet (which was dynamically added to a jquery mobile form):
<li class="ld ui-li-divider ui-bar-inherit" data-role="list-divider"
role="heading">Monday
<label class="dateInput" style="display: none;">Choose a
Date to attend:<input type="text" id="dateInput1" name="dateInput1"
class="dateInput"
data-role="date" data-inline="false" style="display: none;">
</label>
</li>
<li class="hn ui-li-static ui-body-inherit ui-li-has-thumb">
<input type="checkbox" class="catChk" id="chkH10" name="chkH" data-week-
day="Monday" value="">Check1</li>
<li class="hn ui-li-static ui-body-inherit ui-li-has-thumb">
<input type="checkbox" class="catChk" id="chkH11" name="chkH" data-week-
day="Monday" value="">Check2</li>
The elements with class="dateInput" are hidden. When either Check1 or Check2 is checked I want to show the dateInput.
I've tried lots of things including:
$("#dayClassList").on("click", "input.catChk", function () {
$(this).closest(".ld").find(".dateInput").show();
}
Just using $(".dateInput").show(); works, but I have other dateInputs on the page that should stay hidden. I just want the dateInput in the closest ".ld" to be shown. The ids are dynamically created so I can't use them. I have to work with the class selectors.
I also added fiddle link: https://jsfiddle.net/dipakchavda2912/ce9mu1q2/
Let me know is it resolve your issue or not?
<li class="ld ui-li-divider ui-bar-inherit" data-role="list-divider"
role="heading">Monday
<label class="dateInput" style="display: none;">Choose a Date to attend:
<input type="text" id="dateInput1" name="dateInput1"
class="dateInput"
data-role="date" data-inline="false">
</label>
</li>
<li class="hn ui-li-static ui-body-inherit ui-li-has-thumb">
<input type="checkbox" class="catChk" id="chkH10" name="chkH" data-week-
day="Monday" value="">Check1</li>
<li class="hn ui-li-static ui-body-inherit ui-li-has-thumb">
<input type="checkbox" class="catChk" id="chkH11" name="chkH" data-week-
day="Monday" value="">Check2</li>
$(document).ready(function(){
$(".catChk").on("change", function (e) {
if(true === $(this).is(":checked")){
$.each($(".dateInput, input[id^='dateInput']"), function () {
$(this).show();
});
}else{
$.each($(".dateInput, input[id^='dateInput']"), function () {
$(this).hide();
});
}
});
});
$("#dayClassList").on("click", "input.catChk", function () {
$(".dateInput:first").show();
}
Dipak your answer put me on the right track. I have accepted your answer. I ended up kludging it by changing the id of the li.ln to include the dayName. This made it easy to target. When the checkbox is checked I grab the data-week-day value and find the matching li.ln with the same value.
Using jQueryMobile 1.4.5, I need to toggle the presence of the middle button on and off so that the other 2 buttons butt_up against each other if the middle button is gone.
My js script makes it disappear but leaves room between the ouster 2 buttons.
How can this be achieved? Thanks
jQuery.fn.invisible = function() {
return this.css('visibility', 'hidden');
};
jQuery.fn.visibilityToggle = function() {
return this.css('visibility', function(i, visibility) {
return (visibility == 'visible') ? 'hidden' : 'visible';
});
};
$("li:nth-child(2)").invisible();
<footer data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><button type="submit" data-theme="c">NO</button></li>
<li><button type="submit" data-theme="c">EXTRA</button></li>
<li><button type="submit" data-theme="c">YES</button></li>
</ul>
</div>
</footer><!-- footer -->
At the moment there is no jqm method to refresh a navbar. Hopefully we get one with 1.5 ...
But you can manipulate the "grid classes" of the navbar.
I think this is the easiest way if you only want to add/remove one button.
$('#toggle').on("click", function() {
if ($("#navbar > ul").hasClass('ui-grid-b')) {
$("#extra").hide();
$("#navbar > ul").removeClass('ui-grid-b').addClass('ui-grid-a')
.find("li").last().removeClass('ui-block-c').addClass("ui-block-b");
} else {
$("#extra").show();
$("#navbar > ul").removeClass('ui-grid-a').addClass('ui-grid-b')
.find("li").last().removeClass('ui-block-b').addClass("ui-block-c");
}
});
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<button id="toggle">Toggle</button>
<footer data-role="footer" data-position="fixed">
<div data-role="navbar" id="navbar">
<ul>
<li>
<button type="submit" data-theme="c">NO</button>
</li>
<li id="extra">
<button type="submit" data-theme="c">EXTRA</button>
</li>
<li>
<button type="submit" data-theme="c">YES</button>
</li>
</ul>
</div>
</footer>
<!-- footer -->
I'm using ui-boostrap dropdown directive, and want to add my own ng-if to prevent showing it on some cases.
When adding this ng-if, even when it always returns "true" - the dropdown stop working (doesn't pop up). It seems the drop-down button stops receiving ng-click events (therefore not changing the isOpen state..).
HTML:
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.2.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="DropdownCtrl">
<!-- Single button -->
<div class="btn-group" uib-dropdown is-open="status.isopen">
<!-- When putting this ng-if, the drop down stops working -->
<div ng-if="isAllowed()">
<button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
Button dropdown <span class="caret"></span>
</button>
<ul class="uib-dropdown-menu" role="menu" aria-labelledby="single-button">
<li role="menuitem">Action</li>
<li role="menuitem">Another action</li>
<li role="menuitem">Something else here</li>
<li class="divider"></li>
<li role="menuitem">Separated link</li>
</ul>
</div>
</div>
<script type="text/ng-template" id="dropdown.html">
<ul class="uib-dropdown-menu" role="menu" aria-labelledby="button-template-url">
<li role="menuitem">Action in Template</li>
<li role="menuitem">Another action in Template</li>
<li role="menuitem">Something else here</li>
<li class="divider"></li>
<li role="menuitem">Separated link in Template</li>
</ul>
</script>
</div>
</body>
</html>
JS:
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DropdownCtrl', function ($scope, $log) {
$scope.items = [
'The first choice!',
'And another choice for you.',
'but wait! A third!'
];
$scope.status = {
isopen: false
};
$scope.toggled = function(open) {
$log.log('Dropdown is now: ', open);
};
$scope.toggleDropdown = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.status.isopen = !$scope.status.isopen;
console.log('isOpen = ' + $scope.status.isopen);
};
$scope.isAllowed = function() {
return true;
}
});
Here is a plunker reproduce the problem:
http://plnkr.co/edit/8K9MUsDfFcjyiZvFdv5x?p=preview
Any ideas?
Take out the div with the ng-if on it and put the ng-if on the enclosing div, i.e.
<div class="btn-group" uib-dropdown is-open="status.isopen" ng-if="isAllowed()">
<button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
Button dropdown <span class="caret"></span>
</button>
<ul class="uib-dropdown-menu" role="menu" aria-labelledby="single-button">
<li role="menuitem">Action</li>
<li role="menuitem">Another action</li>
<li role="menuitem">Something else here</li>
<li class="divider"></li>
<li role="menuitem">Separated link</li>
</ul>
</div>
I have two tabs with a submit button on each tab. When the button is clicked, I need to reload the content of that specific tab to get updated data from the server.
if (validStatus()) {
$.ajax({
//...
success: reloadTab
});
}
function reloadTab() {
var currentTab = $("#tabs").tabs("option", "active");
alert(currentTab);
$('#tabs').tabs('select', currentTab);
alert(currentTab);
}
When the button is clicked, the tab doesn't refresh. I see the first alert but not the second.
HTML is as follows:
Head:
<link rel="stylesheet" href="#this.Url.Content("//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css")" />
<script>
$(function () {
$("#tabs").tabs();
});
</script>
Body:
<div id="tabs">
<ul>
<li>The first tab</li>
<li>the second tab</li>
<li>Success</li>
</ul>
<div id="Success">
testing
</div>
<div id="Tab1">
<fieldset >
<legend>Overview</legend>
<input type="button" id="submit1" value="submit" />
<br />
</fieldset>
<fieldset style="width: 700px;">
<legend>Overview</legend>
<div>
<table >
//updated with ajax
</table>
</div>
</fieldset>
<script>
//reloadTab is in here
</script>
</div>
<div id="Tab2">
<fieldset style="float:left; width:300px;">
<input id="submit2" type="button" value="submit"/>
</fieldset>
<fieldset style="float:left;">
<legend>Overview</legend>
<table>
//updated with ajax
</table>
</fieldset>
<script>.....</script>
</div>
Turns out tabs.('select', ...) is deprecated, using tabs.('option', 'active', index) fixed my issue. Solution found in this comment: https://stackoverflow.com/a/16033969/1463649
Do you see anything in the console of your browser? What browser are you using?
Try this to help you with the debugging.
function reloadTab() {
console.log($('#tabs')); // if this is an empty object, the element doesn't exist when you call this function
console.log($('#tabs').tabs()); // if this doesn't return 'function', you haven't included a library properly, maybe jquery ui, or jquery, or you're using an old version or something
console.log(currentTab); // if this is undefined then something went wrong and no tab is active
var currentTab = $("#tabs").tabs("option", "active");
alert(currentTab);
$('#tabs').tabs('select', currentTab);
alert(currentTab);
}
I have a single .html file that looks similar to the following:
<div id="myPage" data-role="page">
<div data-role="header">
Back
<h1>My App</h1>
</div>
<div>
<input id="saveButton" type="button" value="Save" onclick="doStuff()" />
</div>
<script type="text/javascript">
function doStuff() {
var updatedText = getUpdatedText();
$("#myMessage", "#myDialog").html(updatedText);
$.mobile.changePage("#myDialog", { role: "dialog" });
}
</script>
</div>
<div id="myDialog" data-role="page">
<div id="myMessage"></div>
<input id="button1" type="button" value="Button 1" data-theme="b" onclick="someJS1();" />
<input id="button2" type="button" value="Button 2" data-theme="c" onclick="someJS2();" />
</div>
When "doStuff()" is called, I want to set a custom message in the text of my dialog and open the dialog. For some reason, I have been unable to open the myDialog. For the life of me, I cannot figure out what I'm doing wrong. I have reviewed the content posted here: http://jquerymobile.com/demos/1.0a4.1/docs/pages/docs-pages.html
I think you need to set the role of the page to dialog
<div id="myDialog" data-role="dialog">
<div id="myMessage"></div>
<input id="button1" type="button" value="Button 1" data-theme="b" onclick="someJS1();" />
<input id="button2" type="button" value="Button 2" data-theme="c" onclick="someJS2();" />
</div>
And then open the dialog with
$.mobile.changePage("#myDialog");
See Fiddle http://jsfiddle.net/kYsVp/2/