views:

14

answers:

0

I am using JQuery Autocomplete in one of my projects, and so far it's working really well.

However, I have come across an issue that has me stumped!

I have it setup as follows:

        $("#display_field").autocomplete({
            source: "myscipt.php",
            minLength: 2,                                                  
            select: function(event, ui) {
                $("#id_field").val(ui.item.id);
            }
        })

I have a text field called display_field where the user enters the text, and a hidden ID field called id_field.

When the user selects an item from the dropdown list, it stores the ID value of the lookup record in the hidden id_field.

So far so good!

The problem is that I've found some users ignore the suggestion list and type the value in full.

e.g. instead of typing "App" and selecting "Apple" from the suggestion list, they are just typing the word "Apple" in full, and so the above select method is never being triggered, and the hidden id_field value is not populated.

I could of course write an onblur function that calls the same script that autoquery does and populate it that way, but I'm wondering if there is any way to do it in autocomplete itself? Seems like a logical behaviour?

Also, if an unmatched value is entered then it should clear the value in id_field.