From 6d643f9e74c32bbcb84d03404ee1cfd4613b6e2a Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 4 Dec 2012 21:21:54 +0100 Subject: multiSelect.js: Give each select a unique msid to prevent double adding in users.js --- core/js/multiselect.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'core/js') diff --git a/core/js/multiselect.js b/core/js/multiselect.js index d41b5d552ab..9e808a2bb72 100644 --- a/core/js/multiselect.js +++ b/core/js/multiselect.js @@ -1,5 +1,7 @@ /** - * @param 'createCallback' A function to be called when a new entry is created. Only argument to the function is the value of the option. + * @param 'createCallback' A function to be called when a new entry is created. Two arguments are supplied to this function: + * The select element used and the value of the option. If the function returns false addition will be cancelled. If it returns + * anything else it will be used as the value of the newly added option. * @param 'createText' The placeholder text for the create action. * @param 'title' The title to show if no options are selected. * @param 'checked' An array containing values for options that should be checked. Any options which are already selected will be added to this array. @@ -23,6 +25,7 @@ 'onuncheck':false, 'minWidth': 'default;', }; + $(this).attr('data-msid', multiSelectId); $.extend(settings,options); $.each(this.children(),function(i,option) { // If the option is selected, but not in the checked array, add it. @@ -189,30 +192,36 @@ if (exists) { return false; } + var li=$(this).parent(); + var val = $(this).val() + var select=button.parent().next(); + if(typeof settings.createCallback === 'function') { + var response = settings.createCallback(select, val); + if(response === false) { + return false; + } else if(typeof response !== 'undefined') { + val = response; + } + } if(settings.singleSelect) { $.each(select.find('option:selected'), function() { $(this).removeAttr('selected'); }); } - var li=$(this).parent(); $(this).remove(); li.text('+ '+settings.createText); li.before(createItem(this)); - if(self.menuDirection === 'up') { - var list = li.parent(); - list.css('top', list.position().top-li.outerHeight()); - } - var select=button.parent().next(); var option=$('