Skip to content

Commit

Permalink
MDL-53730 form: Autocomplete triggers change event on change only
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart authored and andrewnicols committed May 6, 2016
1 parent 456b8a6 commit 1eaba73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 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.

21 changes: 16 additions & 5 deletions lib/amd/src/form-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,21 @@ 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') {
};

/**
* Notify of a change in the selection.
*
* @param {jQuery} originalSelect The jQuery object matching the hidden select list.
* @return {Void}
*/
var notifyChange = function(originalSelect) {
if (typeof M.core_formchangechecker !== 'undefined') {
M.core_formchangechecker.set_form_changed();
}
originalSelect.change();
};


/**
* Remove the given item from the list of selected things.
*
Expand Down Expand Up @@ -146,6 +152,8 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
}
// Rerender the selection list.
updateSelectionList(options, state, originalSelect);
// Notifiy that the selection changed.
notifyChange(originalSelect);
};

/**
Expand Down Expand Up @@ -402,7 +410,8 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
});

updateSelectionList(options, state, originalSelect);

// Notifiy that the selection changed.
notifyChange(originalSelect);
// Clear the input field.
inputElement.val('');
// Close the suggestions list.
Expand Down Expand Up @@ -440,6 +449,8 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
});
// Rerender the selection list.
updateSelectionList(options, state, originalSelect);
// Notifiy that the selection changed.
notifyChange(originalSelect);
// Clear the input element.
inputElement.val('');
// Close the list of suggestions.
Expand Down

0 comments on commit 1eaba73

Please sign in to comment.