Skip to content

Commit

Permalink
MDL-59366 core_amd: Modifications for form-autocomplete
Browse files Browse the repository at this point in the history
* New optional parameter 'closeSuggestionsOnSelect' for the enhance()
function for form-autocomplete. Setting this to true will close the
suggestions popup immediately after an option has been selected. If not
specified, it defaults to true for single-select elements and false
for multiple-select elements.

Part of MDL-59290.
  • Loading branch information
junpataleta committed Jul 28, 2017
1 parent bb1c6f8 commit 198d729
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/amd/build/form-autocomplete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions lib/amd/src/form-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
// Notifiy that the selection changed.
notifyChange(originalSelect);

if (!options.multiple) {
if (options.closeSuggestionsOnSelect) {
// Clear the input element.
inputElement.val('');
// Close the list of suggestions.
Expand Down Expand Up @@ -718,9 +718,11 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
* @param {Boolean} caseSensitive - If search has to be made case sensitive.
* @param {Boolean} showSuggestions - If suggestions should be shown
* @param {String} noSelectionString - Text to display when there is no selection
* @param {Boolean} closeSuggestionsOnSelect - Whether to close the suggestions immediately after making a selection.
* @return {Promise}
*/
enhance: function(selector, tags, ajax, placeholder, caseSensitive, showSuggestions, noSelectionString) {
enhance: function(selector, tags, ajax, placeholder, caseSensitive, showSuggestions, noSelectionString,
closeSuggestionsOnSelect) {
// Set some default values.
var options = {
selector: selector,
Expand Down Expand Up @@ -769,6 +771,13 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
};
options.multiple = originalSelect.attr('multiple');

if (typeof closeSuggestionsOnSelect !== "undefined") {
options.closeSuggestionsOnSelect = closeSuggestionsOnSelect;
} else {
// If not specified, this will close suggestions by default for single-select elements only.
options.closeSuggestionsOnSelect = !options.multiple;
}

var originalLabel = $('[for=' + state.selectId + ']');
// Create the new markup and insert it after the select.
var suggestions = [];
Expand Down
3 changes: 3 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ information provided here is intended especially for developers.
- get_enrolled_with_capabilities_join()
Setting this parameter to a non-zero value will add a condition to the query such that only users that were enrolled
with this enrolment method will be returned.
* New optional parameter 'closeSuggestionsOnSelect' for the enhance() function for form-autocomplete. Setting this to true will
close the suggestions popup immediately after an option has been selected. If not specified, it defaults to true for single-select
elements and false for multiple-select elements.

=== 3.3.1 ===

Expand Down

0 comments on commit 198d729

Please sign in to comment.