From 3084da22382d7849b4dc3eb941ebdf02e2f44497 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 20 Jan 2014 13:45:33 +0000 Subject: [PATCH] Make sure value is numeric. Fixes user/group selection sometimes doubled an option --- etemplate/js/et2_widget_selectAccount.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/etemplate/js/et2_widget_selectAccount.js b/etemplate/js/et2_widget_selectAccount.js index 597789009e..6c7285bcba 100644 --- a/etemplate/js/et2_widget_selectAccount.js +++ b/etemplate/js/et2_widget_selectAccount.js @@ -175,6 +175,9 @@ var et2_selectAccount = et2_selectbox.extend( var self = this; this.search_widget.select = function(e, selected) { var current = self.getValue(); + + // Fix ID as sent from server - must be numeric + selected.item.value = parseInt(selected.item.value); // This one is important, it makes sure the option is there old_select.apply(this, arguments); @@ -379,9 +382,16 @@ var et2_selectAccount = et2_selectbox.extend( }, 'select': function(e, selected) { // Make sure option is there - if(typeof self.options.select_options[selected.item.value] == 'undefined') + var already_there = false; + var last_key = null; + for(last_key in self.options.select_options) { - self.options.select_options[selected.item.value] = selected.item; + var option = self.options.select_options[last_key]; + already_there = already_there || (typeof option.value != 'undefined' && option.value == selected.item.value); + } + if(!already_there) + { + self.options.select_options[parseInt(last_key)+1] = selected.item; self._appendOptionElement(selected.item.value, selected.item.label); } self.set_value(selected.item.value); @@ -416,7 +426,9 @@ var et2_selectAccount = et2_selectbox.extend( // Don't show normal drop-down search_widget.search.data("ui-autocomplete")._suggest = function(items) { jQuery.each(items, function (index, item) { - self._add_search_result(results, item); + // Make sure value is numeric + item.value = parseInt(item.value); + self._add_search_result(results, item); }); };