Why does the jquery ui autocomplete function reduce support for these functions?

jquery UI team has a blog on how to replace obsolete autocomplete, and justifies its ability to replicate all old functions and parameters . Based on my testing, I do not think that they can be replicated:

  • selectFirst if you have a remote data source
  • selectFirst or mustMatch if you use multiple: true

I see these questions about how to copy some of the obsolete autocomplete from this plugin , and there is a selected answer, but it does not affect these situations.

In jquery ui , people have an example of selectFirst replication in the new autocomplete , but if I'm not mistaken, it works only with the local data source (and not with the remote data source, since the menu usually does not fill up before the event is raised).

Am I missing something or are these scripts simply not supported in jquery ui autocomplete?

+6
jquery jquery-ui autocomplete
source share
1 answer

These scripts are actually supported, but you must extend the ui.autocomplete widget to achieve the desired behavior. A quick example of the implementation of the selectFirst function:

$.widget( "ui.autocomplete2", $.ui.autocomplete, { _renderMenu: function( ul, items ) { var self = this; $.each( items, function( index, item ) { self._renderItem( ul, item ); }); // setTimeout is needed because jQueryUI automaticaly removes // active item just after menu rendering setTimeout( function(){ self.menu.activate( // fake event object. Needed to avoid jQueryUI error // (unsafe property access) {'type':'fake'}, ul.find(':first') ); }, 1); } }); 

Attention Always check if the new widget is compatible with the new version of jQuery UI!

Update: an example implementation of mustMatch can be found here: http://jqueryui.com/demos/autocomplete/combobox.html

+6
source share

All Articles