Here is how I did it:
- I store the selected value in the selected event in an attribute of the HTML element called "ac-selected-value".
- when focusing, I check if the value matches the saved one, and if not, clears the value
"" "" ( , ), - , devBridgeAutocomplete :
$.MyNamespace.fs.autocomplete = function (elems, options) {
elems.devbridgeAutocomplete(options);
elems.focusout(function (e) {
var txt = $(this);
if (txt.attr("ac-selected-value") !== txt.val()) {
txt.val("");
}
});
};
...
$.Autocomplete.defaults.autoSelectFirst = true;
$.Autocomplete.defaults.onSelect = function (suggestion) {
$(this).attr("ac-selected-value", suggestion.value);
};
...
$.Autocomplete.defaults.onInvalidateSelection = function () {
$(this).val("");
};
, - , , :
$.MyNamespace.fs.autocomplete($("#select-something"), {
serviceUrl: 'some-url'
});
, :
$("#select-something").devbridgeAutocomplete({
serviceUrl: 'some-url'
});