MDL-55988 Forms: Stop autocomplete triggering warning on unload
Prevents autocomplete fields marking a form "dirty" when initialised, and allows them to honour the "ignoredirty" class.
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -368,8 +368,12 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
* @param {Object} options Original options for this autocomplete element.
|
||||
* @param {Object} state State variables for this autocomplete element.
|
||||
* @param {JQuery} originalSelect The JQuery object matching the hidden select list.
|
||||
* @param {boolean} markDirty Should the form be marked dirty after this update?
|
||||
*/
|
||||
var updateSelectionList = function(options, state, originalSelect) {
|
||||
var updateSelectionList = function(options, state, originalSelect, markDirty) {
|
||||
if (markDirty === undefined) {
|
||||
markDirty = true;
|
||||
}
|
||||
// Build up a valid context to re-render the template.
|
||||
var items = [];
|
||||
var newSelection = $(document.getElementById(state.selectionId));
|
||||
@@ -402,8 +406,8 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
}).fail(notification.exception);
|
||||
// Because this function get's called after changing the selection, this is a good place
|
||||
// to trigger a change notification.
|
||||
if (typeof M.core_formchangechecker != 'undefined') {
|
||||
M.core_formchangechecker.set_form_changed();
|
||||
if (typeof M.core_formchangechecker != 'undefined' && markDirty) {
|
||||
M.core_formchangechecker.set_form_changed({target: originalSelect});
|
||||
}
|
||||
originalSelect.change();
|
||||
};
|
||||
@@ -726,6 +730,7 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
var context = $.extend({}, options, state);
|
||||
context.options = suggestions;
|
||||
context.items = [];
|
||||
context.class = originalSelect.attr('class');
|
||||
|
||||
var renderInput = templates.render('core/form_autocomplete_input', context);
|
||||
var renderDatalist = templates.render('core/form_autocomplete_suggestions', context);
|
||||
@@ -759,7 +764,7 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
});
|
||||
}
|
||||
// Show the current values in the selection list.
|
||||
updateSelectionList(options, state, originalSelect);
|
||||
updateSelectionList(options, state, originalSelect, false);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
{ "inputID": 1, "suggestionsId": 2, "selectionId": 3, "downArrowId": 4, "placeholder": "Select something" }
|
||||
}}
|
||||
{{#showSuggestions}}
|
||||
<input type="text" id="{{inputId}}" list="{{suggestionsId}}" placeholder="{{placeholder}}" role="combobox" aria-expanded="false" autocomplete="off" autocorrect="off" autocapitalize="off" aria-autocomplete="list" aria-owns="{{suggestionsId}} {{selectionId}}"/><span class="form-autocomplete-downarrow" id="{{downArrowId}}">▼</span>
|
||||
<input type="text" id="{{inputId}}" {{#class}}class="{{class}}" {{/class}}list="{{suggestionsId}}" placeholder="{{placeholder}}" role="combobox" aria-expanded="false" autocomplete="off" autocorrect="off" autocapitalize="off" aria-autocomplete="list" aria-owns="{{suggestionsId}} {{selectionId}}"/><span class="form-autocomplete-downarrow" id="{{downArrowId}}">▼</span>
|
||||
{{/showSuggestions}}
|
||||
{{^showSuggestions}}
|
||||
<input type="text" id="{{inputId}}" placeholder="{{placeholder}}" role="textbox" aria-owns="{{selectionId}}"/>
|
||||
<input type="text" id="{{inputId}}" {{#class}}class="{{class}}" {{/class}} placeholder="{{placeholder}}" role="textbox" aria-owns="{{selectionId}}"/>
|
||||
{{/showSuggestions}}
|
||||
|
||||
Reference in New Issue
Block a user