Select2验证 - 选择一个值的最低值



我正在使用select2和jQuery验证插件。

select2:

的html
<div class="form-group">
<label for="select2Region"><h3>Set Location</h3></label><br />
<input type="hidden" id="select2Region" style="width:40%" required/>
</div>

select2启动:

        $('#select2Region').select2({
            minimumInputLength: 1,
            data: $.parseJSON(selectRegion),
            placeholder: "Enter your City here",
            allowClear: true
        });

数据填充完美。现在,我希望用户选择一个值。

如GitHub中所述,我尝试了:

尝试添加忽略:'',在规则直接的行中:。自忽略:null,不起作用以来,一个空字符串为我完成了工作。

也是如此:

$('.select2').select2().change(function(){
   $(this).valid();
});

,但他们俩都不为我工作。这样做的正确方法是什么?

jQuery Validate代码

        $("#myForm").validate({
          ignore: '',
          messages: {
            select2Start: {
              required: "Please select your starting point.",
            }
          }
        });

n我的HTML代码如下:

<div class="form-group">
  <label for="select2Region"><h3>Set Location</h3></label><br />
  <input type="hidden" id="select2Region" name="select2Region" style="width:40%" required/>
</div>

希望有帮助!

最新更新