Jquery.tokeninput required

I have this fantastic little plugin, but I need at least one name to be selected. I usually use jquery.validate. However, the validation plugin does not work in the field using tokeninput. Does anyone have an answer? As always, many thanks 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..." }) 
+4
source share
2 answers

I had the same problem and decided to ignore it (obviously, the problem is that tokenInput hides the original input and by default "validate" does not check hidden inputs)

 $("#NewMessage").validate({ ignore: "", rules: { name: { required: true } } }); 
+8
source

I wrote and tried, It works great for 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" } }); 
0
source

Source: https://habr.com/ru/post/1402724/


All Articles