jquery - Autocomplete doesn't fire select function if tab out of input quickly -


i have configured autocomplete on input, delay option set 0, , autofocus set true. source: autocomplete set ajax call. typically, if user inputs search string , tabs out of field, first item selected.

however, if experienced user inputs search string should have 1 match , very quickly tabs out of input, function specified select option doesn't fire, , input contains search string user entered. causing error when form submitted, because valid selection hasn't been made (normally, selection of match sets hidden form field value of selected match).

if put breakpoint in function specified source option retrieve matches, can see invoked, , gets list of matches back. however, breakpoint put in function specified select option never hit when tab out quickly.

i can reproduce behavior in both chrome , ie 11, when running against localhost or remote webserver. jquery-ui version v1.11.4.

question: possible configure autocomplete -always- select first returned match if user enters search string , tabs out of input, no matter how quickly?

the autocomplete "disabled" if focus set out of relevant input, don't have access values of autocomplete if move focus input.

this solution work only if menu triggered (and opened):

var availabletags = [    "actionscript",    "applescript",    "asp",    "basic",    "c",    "c++",    "clojure",    "cobol",    "coldfusion",    "erlang",    "fortran",    "groovy",    "haskell",    "java",    "javascript",    "lisp",    "perl",    "php",    "python",    "ruby",    "scala",    "scheme"  ];  $( "#tags" ).autocomplete({    source: availabletags,    autofocus: true,    delay: 0,    focus: function(event, ui) {      $(this).val(ui.item.value)    }  });
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">  <link rel="stylesheet" href="/resources/demos/style.css">  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  <div class="ui-widget">    <label for="tags">tags: </label>    <input id="tags">  </div>

the delay there set 0 there no delay, if source ajax call - have delay there (and if user move move focus other element result not looking for).

i know it's not looking for, if work predefined values can give solution.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -