MDL-51324 forms: fix autocomplete element double selection bug
Incorrect types were preventing the currently selected values from being removed from the new values returned via ajax. Also fix a selection bug with autocomplete+ajax+singleselect.
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -469,12 +469,20 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
if (!option.prop('selected')) {
|
||||
option.remove();
|
||||
} else {
|
||||
existingValues.push(option.attr('value'));
|
||||
existingValues.push(String(option.attr('value')));
|
||||
}
|
||||
});
|
||||
|
||||
if (!options.multiple && originalSelect.children('option').length === 0) {
|
||||
// If this is a single select - and there are no current options
|
||||
// the first option added will be selected by the browser. This causes a bug!
|
||||
// We need to insert an empty option so that none of the real options are selected.
|
||||
var option = $('<option>');
|
||||
originalSelect.append(option);
|
||||
}
|
||||
// And add all the new ones returned from ajax.
|
||||
$.each(processedResults, function(resultIndex, result) {
|
||||
if (existingValues.indexOf(result.value) === -1) {
|
||||
if (existingValues.indexOf(String(result.value)) === -1) {
|
||||
var option = $('<option>');
|
||||
option.append(result.label);
|
||||
option.attr('value', result.value);
|
||||
|
||||
Reference in New Issue
Block a user