jquery.tokeninput required

半腔热情 提交于 2020-01-02 05:42:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!