I am trying to validate jquery autocomplete to select only from the prepopulated list.I have done this in the autocomplete change event as below :
$( "#supcode" ).autocomplete({
source:tags,
//To select only from the autocomplete
change: function (event, ui) {
if (ui.item == null || ui.item == undefined) {
$("#supcode").val("");
$("#supcode").attr("disabled", false);
}
// else {
// $("#supcode").attr("disabled", true);
// }
}
});
This will not be checked if the user clicks the submit button without blurring from the autocomplete textbox.Therefore I want to validate it in jquery validate in the required like given below:
$("#form").validate({
// Specify the validation rules
rules:{
supcode:{
required:
function(){
//Check if the value in input is from prepopulated list
},
}
}
submitHandler: function(form) {
form.submit();
}
});
How do I check if the value is from the autocomplete list?