|
-
Aug 6th, 2012, 07:46 AM
#9
Thread Starter
Hyperactive Member
Re: Seems I cannot check a checkbox in jQuery
I got it working now (phew!)....but ONLY if I put in breakpoints in FireBug when binding to the events.
Otherwise it seems the modal.show get called before it the binding to the show even occured, and then my checkboxes won't get checked.
While "off the topic" can someone look at my (first) plugin and tell me where I'm going wrong?
Code:
(function ($) {
$.fn.extend({
// Used to open a modal, listing all service providers
// Callback will return selected service providers
selectServiceProviders: function (options, callback) {
var defaults = {
url: '', // must be set to url to action returning service providers selection form
currentSelection: '' // currently selected items
};
options = $.extend(defaults, options);
return this.each(function () {
var url = options["url"];
$('#modalContent', this).load(url);
// Bind to Show Event : See if we have a current selection and if so check off checkboxes accordingly
$(this).bind('show', function () {
var currentSelection = options["currentSelection"];
if (currentSelection != '') {
$('[name=chkProviders]:checkbox').each(function () {
if (jQuery.inArray($(this).attr("id"), currentSelection) > -1) {
$(this).attr("checked", "checked");
}
});
}
});
// Bind to Hide Event : Call the callback function when we close
$(this).bind('hidden', function () {
if (typeof callback == 'function') {
var selectedIds = new Array();
var selectedNames = new Array();
$('input[name=chkProviders]:checked').each(function () {
selectedIds.push($(this).attr('id'));
selectedNames.push($(this).attr('value'));
});
callback.call(this, selectedIds, selectedNames);
}
});
// PROBLEM: this should fire AFTER binding, but it does not (unless i have a breakpoint)
$(this).modal('show');
});
}
});
})(jQuery);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|