In my ASP.Net MVC application I have a jQuery autocomplete on a text box. I have everything working to display currently used item names and what I want to do is force the user to enter a completely NEW item name. I.e. the autocomplete acts as a guide to what exists but the user must ultimately enter a completely used string value.
I want the UI to signal if a currently used item is selected (there will be anther check on the server side when submit is posted) so for the moment there is just a simple alert().
My script is as follows:
$(document).ready(function() {
$('#combobox').autocomplete('<%= Url.Action("ProjectIdList", "LookUp") %>', {
delay:10,
minChars:1,
matchCase: 0,
matchSubset: 1,
autoFill: true,
maxItemsToShow:10,
cacheLength: 10,
onItemSelect:selectItem,
onFindValue:selectItem
});
});
Please note the markup: onItemSelect:selectItem, onFindValue:selectItem
I have further script as follows:
function findValue(li) {
if (li != null) return alert("This Project Id cannot be used");
}
function selectItem(li) {
findValue(li);
}
However, I cannot get these events to fire. What am I missing?
Alternatively, is there a better way to do this?