Is there a jQuery Autocomplete plugin that forces me to select an element?

There autocomplete , but it does not force the selection of the item. I need something like this, but it should make the item be selected before you can "send".

He exists?

+5
source share
6 answers

This is my solution with .blur (moreover, I use ID ID pairs)

jQuery("#username").autocomplete(
    "/yii_app/stock/suggestUser",
    {
        'mustMatch':true,
        'multiple':false,
        'formatItem':function(result, i, num, term) {
            return '<small>'+result[1]+'</small>&nbsp;&nbsp;&nbsp;'+ result[0];
        }
    }
).result(
    function(event,item) {
        $("#user_id").val(item[1]);
    }
).blur(
    function() {
        $("#user_id").val('');
        $(this).search();
    }
);

user_id - hidden input field, username - text input field Result ajax uses the following format: user1name | user1id \ n user2name | user2id \ n

+2
source

You can use the "change" AutoFill event

        var availableTags = [
            "ActionScript",
            "AppleScript"
        ];
        $("#tags").autocomplete({
            source: availableTags,
            change: function (event, ui) {
                if(!ui.item){
                    //http://api.jqueryui.com/autocomplete/#event-change -
                    // The item selected from the menu, if any. Otherwise the property is null
                    //so clear the item for force selection
                    $("#tags").val("");
                }

            }

        });
+4
source

:

mustMatch:true,

Bassistance. Ii , jQuery Bassistance, !

+1

, jQuery UI autocomplete:

    $('#some-input').autocomplete({
        source: 'some-url',
        autoFocus: true,
        minLength: 2,
        select: function(event, ui) {
            //remember the selected item
            $('#some-input')
                .data('selected-item', ui.item.label);
        }
    }).blur(function() {
        var value = $('#some-input').val();
        //check if the input value matches the selected item
        if(value != $('#some-input').data('selected-item')) {
            //they don't, the user must have typed something else
            $('#some-input')
                .val('') //clear the input text
                .data('selected-item', ''); //clear the selected item
        }
    });

, , . ( , , select ), "selected-item" . , ( , - ).

+1

validation. required .

0
source

You can also use the built-in send event

$('Autocomplete').autocomplete({
          select: function(event, ui) {
                       $('submit').show();
                  }
});
0
source

All Articles