I'm using jquery ui(1.8.11) autocomplete plugin.
It has a simple custom behavior to check whether the value exists in the available list. That's because I want to restrain the user to what is available in the list. If input is not in the list it will erase the content of the box. It's working fine.
But the following implementation still allow the user to write anything that's not in the choices. I would prefer not letting him write something that doesn't exist.
So is there a way to erase characters that the user would write as soon as there is no option left ? Or better only letting him hit a sequence of characters if it has a lookup in the list.
Here is my code so far
$("#autocomplete").autocomplete({
autoFocus: true,
delay: 200,
source: function (request, response) {
$.ajax({
url: "/Country/Find", type: "GET", dataType: "json",
data: { search: request.term, maxResults: 10 },
success: function (data) {
response($.map(data, function (item) {
return { label: item, value: item }
}))
}
})
},
change: function (event, ui) {
if (!ui.item) {
$(this).val('');
}
}
});