JQuery autocomplete is not supported

When using jQueryUI autocomplete with the AutoFocus parameter set to true, if you type too quickly and press Enter, the first choice will replace the value you entered, even if it doesn't match.

For example, if you type “application” and the first choice of scrollable autofill is “apple”, then continue to type “application” quickly and press “enter”, “application” is replaced by “apple”,

Just before the entered text is replaced with the first choice from autocomplete, is there a way to make sure that the first choice still matches the entered text?

+5
source share
2 answers

Reduce the delay in autocomplete options. If you use local data, you can set the delay to 0. By default, it is set to 300 (ms). Thus, after a key is pressed, it takes 300 ms before it re-evaluates the data set for matches.

So, basically, your autofocus on the first element did not allow him to filter before getting into it.

Alternatively, you can change the average delay stream after the first autofocus. So, the first time you wait 300 ms to show a sentence, then in the focus event you decrease the timer to 0 ms so that it filters out the list faster.

Be careful, since a delay of 0 can cause problems if it is deleted data. Something like this might work well:

$(".selector").autocomplete({
  delay: 300,
  focus: function () {
    $(".selector").autocomplete("option", "delay", 0);
  },
  source: sourceData
}
+3

, , . , . , .

:)

jquery-ui-1.8.20.custom.js( , ), :

                blur: function( event, ui ) {
                // don't set the value of the text field if it already correct
                // this prevents moving the cursor unnecessarily
                if ( self.menu.element.is(":visible") &&
                    ( self.element.val() !== self.term ) ) {
                    self.element.val( self.term );
                }
            }

, if statement :

                blur: function( event, ui ) {
                // don't set the value of the text field if it already correct
                // this prevents moving the cursor unnecessarily
                /*COMMENTING THIS IF OUT MAKES AUTOCOMPLETE STOP ERASING WHAT YOU TYPE
                if ( self.menu.element.is(":visible") &&
                    ( self.element.val() !== self.term ) ) {
                    self.element.val( self.term );
                }
                */
            }

:)

0

All Articles