开发者

jQuery UI Autocomplete with Chrome-like autofill

开发者 https://www.devze.com 2023-01-13 01:49 出处:网络
I\'m using the jQuery UI autocomplete functionality and, while I\'ve found a way to implement the autoFill function, I was looking for fun开发者_JS百科ctionality like in the Google Chrome address bar.

I'm using the jQuery UI autocomplete functionality and, while I've found a way to implement the autoFill function, I was looking for fun开发者_JS百科ctionality like in the Google Chrome address bar. Where the best matching item is auto-filled, but it doesn't interrupt your typing.

jQuery UI Autocomplete with Chrome-like autofill

Any help is appreciated.


I suggest you look at the older jQuery autocomplete plugin, which offers this option built in. The syntax is similar, but instead of having the source as a option you instead initialized it as the first parameter, with this syntax:

$('input.autocomplete').autocomplete(data, {autoFill: true});

The data must be either an array of results, or an url that points to a server-side script that generates it. For more info see its documentation: http://docs.jquery.com/Plugins/Autocomplete


Do note however that the author of this plugin consider it obsolete, and the jQuery UI autocomplete to be its successor. In a 'How to migrate' post he points users now to, the rational jQuery UI not having the autofill option is explained:

autoFill: Gone with no immediate replacement available, for good reasons: The default behaviour when selecting items via keyboard now puts the focussed value into the input, like the Firefox Awesomebar does it. It's not the same as what the autoFill option did, but there should be no need to recreate that effect.


$('#FELD').autocomplete( 
      source: "ajax/manager.json.php",
      minLength: 0, 
      change: function(event, ui) {
          found = false;
            $(".ui-autocomplete li").each(function(n, element){
              var retval = $(element).text().toUpperCase();
              var retval2 = $($(this).data()).attr('item.autocomplete');
              if ((found == false ) &&(retval == $("#FELD").val().toUpperCase()) )
              {
                $("#FELD").val(retval);
                $("#FELDID").val(retval2.id);
                found = true;
              }
            });
          if ( found == false) { $("#FELDID").val("-1"); }
      }
  }); `enter code here`
0

精彩评论

暂无评论...
验证码 换一张
取 消