Here's the full plugin script. I'm not sure if it got anyhing to do with my content (the list with checkboxes) being loaded at runtime (asp.net mvc partial view)
plugin:
and the code in my viewCode:(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"]; var currentSelection = options["currentSelection"].split(','); $('#modalContent', this).load(url); if (currentSelection != '') { $('[name=selectedProviders]:checkbox').each(function () { var id = $(this).attr("id"); if (jQuery.inArray(id, currentSelection) > -1) { $(this).prop("checked", true); } }); }; $(this).modal('show'); $(this).bind('hidden', function () { if (typeof callback == 'function') { var selectedIds = new Array(); var selectedNames = new Array(); $('input[name=selectedProviders]:checked').each(function () { selectedIds.push($(this).attr('id')); selectedNames.push($(this).attr('value')); }); callback.call(this, selectedIds, selectedNames); } }); }); } }); })(jQuery);
Code:$('#manageServiceProviders').click(function () { $('#modalTemplate').selectServiceProviders( { url: '@Url.Action(MVC.Admin.ServiceProvider.GetProviderListForSelection(Model.Partner.Id))', currentSelection: $('#SelectedProviderIds').val() }, function (selectedIds, selectedNames) { $('#SelectedProviderIds').val(selectedIds); $('#SelectedProviderNames').text(selectedNames.join(", ")); } ); event.preventDefault(); });




Reply With Quote