diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-12-04 21:21:54 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-12-04 21:21:54 +0100 |
commit | 6d643f9e74c32bbcb84d03404ee1cfd4613b6e2a (patch) | |
tree | 291a201db438b17ad9cedfc9a4ed8e6e2e948c94 /core/js/multiselect.js | |
parent | 95bdfdb3199f2d2b368e7ded27c09acfc00cdd00 (diff) | |
download | nextcloud-server-6d643f9e74c32bbcb84d03404ee1cfd4613b6e2a.tar.gz nextcloud-server-6d643f9e74c32bbcb84d03404ee1cfd4613b6e2a.zip |
multiSelect.js: Give each select a unique msid to prevent double adding in users.js
Diffstat (limited to 'core/js/multiselect.js')
-rw-r--r-- | core/js/multiselect.js | 29 |
1 files changed, 19 insertions, 10 deletions
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=$('<option selected="selected"/>'); + option.text($(this).val()).val(val).attr('selected', 'selected'); select.append(option); - option.text($(this).val()).val($(this).val()).attr('selected', 'selected'); li.prev().children('input').prop('checked', true).trigger('change'); button.parent().data('preventHide',false); button.children('span').first().text(settings.labels.length > 0 ? settings.labels.join(', ') : settings.title); - if(typeof settings.createCallback === 'function') { - settings.createCallback($(this).val()); + if(self.menuDirection === 'up') { + var list = li.parent(); + list.css('top', list.position().top-li.outerHeight()); } } }); |