Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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 ??

like image 893
leora Avatar asked Feb 20 '11 15:02

leora


People also ask

What is jQuery UI autocomplete?

Autocomplete mechanism is frequently used in modern websites to provide the users a list of suggestion while typing the beginning word in the text box. It facilitates the user to select an item from the list, which will be displayed in the input field.

How to set autocomplete value using jQuery?

To enable an autocomplete in jQuery UI, we will be using the enable() method. jQuery UI enable() method is used to enable the autocomplete.

What is jQuery UI used for?

jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice.


1 Answers

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

like image 139
jrumbinas Avatar answered Oct 13 '22 14:10

jrumbinas