如何使select2与jquery.validation插件一起使用? [英] How to make select2 work with jquery.validation plugin?

查看:284
本文介绍了如何使select2与jquery.validation插件一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jquey.validation插件来验证select2字段,但没有任何反应.

I'm trying to validate select2 field using jquey.validation plugin but nothing happens.

我要选择必填字段.

我正在使用此自定义验证功能:

I'm using this custom validation function:

$.validator.addMethod("requiredcountry", function(value, element, arg){
              return arg != value;
         }, "Value must not equal arg.");

这是规则:

rules:
{
 country:
 {
         required: true,
         requiredcountry: ""
 }
}

我应该使用哪个select2字段来匹配规则?

What select2 field should I use for the rule to match?

我很欣赏如何使select2与jquery.validation一起工作的任何想法

I appreciate any idea how to make select2 working together with jquery.validation

10倍

推荐答案

只需在表单验证功能中添加ignore: [],.它将启用隐藏字段验证.因此,您将获得Select 2的验证

Just add ignore: [], in Your form validation function. It will enable hidden field validation.So You will get validation for Select 2

$("#ContactForm").validate({
  ignore: [],       
  rules: {
    //Rules
  },
  messages: {
    //messages
  }
});

这篇关于如何使select2与jquery.validation插件一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆