开发者

Why did jquery ui autocomplete drop support for these feautures?

the jquery UI team has a blog on how to replace the legacy autocomplete and justifies that it can replicate all of the old features and options. Based on my testing, i dont think they can replicate:

  1. selectFirst if you have a remote data source
  2. selectFirst or mustMatch if you are using multiple: true

i see this questions on how to replicate some of 开发者_StackOverflow中文版the legacy autocomplete options from this plugin, and there is a selected answer but it doesn't address these situations.

The jquery ui folks have an example of replicating selectFirst in the new autocomplete, but unless i am mistaken, it only works with local data source (not remote data source as the menu is usally not filled out before the event get called).

am i missing something or are these scenarios simply not supported in jquery ui autocomplete ??


These scenarios are supported actually, but you have to extend ui.autocomplete widget to achieve desired behavior. Quick example to implement selectFirst feature:

$.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 new widget is still compatible with new version jQuery UI!

Update: sample mustMatch implementation han be found here: http://jqueryui.com/demos/autocomplete/combobox.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜