问题
I am using select2 and jQuery Validation plugins.
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 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.
As is mentioned in Github, i tried this:
Try adding ignore: '', in the line directly above rules:. An empty string did the job for me since ignore: null, wasn't working.
and this as well:
$('.select2').select2().change(function(){
$(this).valid();
});
But they both are not working for me. What is the proper way of doing this?
回答1:
jQuery Validate Code
$("#myForm").validate({
ignore: '',
messages: {
select2Start: {
required: "Please select your starting point.",
}
}
});
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>
Hope that helps!
来源:https://stackoverflow.com/questions/21344481/select2-validation-select-a-minimum-of-one-value