views:

61

answers:

1

So I am working with ASP.Net MVC + jQuery autocomplete and I have a field where I enter an employee. As of right now I have it autocompleting on the employee name and populating a hidden field with the employee id (ajax returns a json object). With autofill set to true it is guaranteed to enter a valid employee id if their search yields a match, but I don't believe it's good practice to allow them to enter some bogus non-autocompleted name when they submit as it will only result in an error.

Is there any way to allow only autocompleted values in the text box? I'd like this to be as solid as possible (not using the blur event allowing them to use a bad value for a short period of time).

UPDATE

I'm apparently blind as I have just discovered the mustMatch option. I'm not sure if I should delete this or not as I've answered my own question. I will leave it up here in case anyone else needs to know or until someone tells me it should be deleted.

+3  A: 

The jquery autocomplete plugin has a must match option. It's in the documentation. This is something from my own code, it has more, but you get the point.

 $('.myfav').live("click", function () {
     autocomplete("somefile.php", {max: 15, mustMatch: true})
 });
Chris