devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.56k stars 1.66k forks source link

attempt of fixing #684 #751

Closed elektronika-ba closed 5 years ago

elektronika-ba commented 5 years ago

Calling of options.onInvalidateSelection in onBlur timer if value has been changed.

netmou commented 5 years ago
      onBlur: function () {
            var that = this,
                options = that.options,
                value = that.el.val(),
                query = that.getQuery(value);

            // If user clicked on a suggestion, hide() will
            // be canceled, otherwise close suggestions
            that.blurTimeoutId = setTimeout(function () {
                that.hide();
// if selection is null auto pick a exact one is better
              if (that.selection == null) {
                    var is_matched = false;
                    for (var index in that.suggestions) {
                        var itVal = that.getValue(that.suggestions[index].value);
                        if (itVal == query) {
                            that.onSelect(index);
                            is_matched = true;
                            break;
                        }
                    }
                    if (!is_matched) { 
                      (options.onInvalidateSelection || $.noop).call(that.element);
                    }
                } else if (that.selection && that.currentValue !== query) {
                    (options.onInvalidateSelection || $.noop).call(that.element);
                }
            }, 200);
        },