MDL-59867 autocomplete: Prevent duplicate ids.

Rendering a form with 2 autocompletes in it can get messed up because of duplicated ids.
This commit is contained in:
Damyon Wiese 2017-08-28 11:55:30 +08:00
parent b3cfb01316
commit b7df2485e6
2 changed files with 11 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -37,6 +37,8 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
UP: 38
};
var uniqueId = $.now();
/**
* Make an item in the selection list "active".
*
@ -786,11 +788,15 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
// Find or generate some ids.
var state = {
selectId: originalSelect.attr('id'),
inputId: 'form_autocomplete_input-' + $.now(),
suggestionsId: 'form_autocomplete_suggestions-' + $.now(),
selectionId: 'form_autocomplete_selection-' + $.now(),
downArrowId: 'form_autocomplete_downarrow-' + $.now()
inputId: 'form_autocomplete_input-' + uniqueId,
suggestionsId: 'form_autocomplete_suggestions-' + uniqueId,
selectionId: 'form_autocomplete_selection-' + uniqueId,
downArrowId: 'form_autocomplete_downarrow-' + uniqueId
};
// Increment the unique counter so we don't get duplicates ever.
uniqueId++;
options.multiple = originalSelect.attr('multiple');
if (typeof closeSuggestionsOnSelect !== "undefined") {