views:

413

answers:

4

There's something like this http://docs.jquery.com/Plugins/Autocomplete/autocomplete, but it doesn't force the selection of an item. I need something like this but it has to force an item to be selected before you can "submit".

Any help?

A: 

This one can be configured to not force anything.

fsb
I WANT to force selection..
Shamoon
Sorry, I misunderstood what "it" was referring to in your question. Have you tried the `autoFill` and/or `mustMatch` options?
fsb
A: 

Use it in combination with the validation plugin. Just make the field required for the validation plugin.

tvanfosson
+1  A: 

This is my solution with .blur (moreover I use name|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 is a hidden input field, username is an text input field ajax result uses the following format: user1name|user1id\n user2name|user2id\n

sis
A: 

Use mustMatch:true, option. This is available in Bassistance autocomplete plugin..i do not know if it is a part of JQuery autocomplete or of bassistance's autocomplete, but it works!

Bhoomi