select2 validation - 选择至少一个值 [英] select2 validation - Select a minimum of one value
本文介绍了select2 validation - 选择至少一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 select2 和 jQuery Validation 插件。
select2的HTML:
HTML for select2:
<div class="form-group">
<label for="select2Region"><h3>Set Location</h3></label><br />
<input type="hidden" id="select2Region" style="width:40%" required/>
</div>
select2启动:
select2 Initiation:
$('#select2Region').select2({
minimumInputLength: 1,
data: $.parseJSON(selectRegion),
placeholder: "Enter your City here",
allowClear: true
});
数据填充完全正常。现在,我希望用户选择一个值。
Data is populating perfectly fine. Now, i want users to select a value.
如上所述在Github中,我试过这个:
As is mentioned in Github, i tried this:
尝试在上面的行中添加ignore:''规则:。一个空字符串为我完成了这项工作,因为忽略:null,无效。
Try adding ignore: '', in the line directly above rules:. An empty string did the job for me since ignore: null, wasn't working.
这也是:
$('.select2').select2().change(function(){
$(this).valid();
});
但他们都不适合我。这样做的正确方法是什么?
But they both are not working for me. What is the proper way of doing this?
推荐答案
jQuery验证码
$("#myForm").validate({
ignore: '',
messages: {
select2Start: {
required: "Please select your starting point.",
}
}
});
我的HTML代码是这样的:
n my HTML code goes like this:
<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>
希望有所帮助!
这篇关于select2 validation - 选择至少一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文