Is it possible to disallow free text entry in the JQuery UI autocomplete widget?
eg I only want the user to be allowed to select from the list of items that are presented in the autocomplete list, and dont want them to be able to write some random text.
I didn't see anything in the demos/docs describing how to do this.
http://jqueryui.com/demos/autocomplete/
I'm using autocomplete like this
$('#selector').autocomplete({
source: url,
minlength: 2,
select: function (event, ui) {
// etc
}
One way would be to use additional validation on form submit (if you are using a form) to highlight an error if the text isn't one of the valid option.
Another way would be to attach to the auto complete's change event which will get fired even if an options isn't selected. You can then do validation to ensure the user input is in your list or display an error if it is not.