问题
I have this fantastic little plugin working but I need to require that at least one name be selected. I normally use jquery.validate. However, the validation plugin does not appear to work on a field using the tokeninput. Does anyone have an answer? As always, thanks so much for your help.
$("#NewMessage").validate({
rules: {
name: {
required: true
}
}
});
$("#name").tokenInput("lookup.cfc?method=getNames&returnFormat=json", {
hintText: "Type in the name of recipient(s)",
noResultsText: "No results",
searchingText: "Searching..."
})
回答1:
I had the same issue and solved it overriding ignore (apparently the problem is that tokenInput hides the original input and by default "validate" doesn't validate hidden inputs)
$("#NewMessage").validate({
ignore: "",
rules: {
name: {
required: true
}
}
});
回答2:
I wrote and tried,It's working fine to me.
jQuery.validator.addMethod("autocomplete_check", function(value, element) {
return ( value != '' ) ? true : false;
}, "");
$("#NewMessage").validate({
ignore: "",
rules: {
name: {
autocomplete_check: true
}
},
messages: {
autocomplete_check: "Please fill the name"
}
});
来源:https://stackoverflow.com/questions/9811028/jquery-tokeninput-required