Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
57
rated 0 times [  58] [ 1]  / answers: 1 / hits: 13787  / 11 Years ago, fri, january 17, 2014, 12:00:00

I have a problem using bootstrap select plugin and jQuery validation. when i select value, error message This field is required not remove While normal validation(without bootstrap select plugin) after select value error message auto remove. how to fix this problem?



JSFIDDLE



HTML:



<form id=myform> <----With Select Plugin
<select name=year class=selectpicker>
<option value=>Year</option>
<option value=1>1955</option>
<option value=2>1956</option>
</select>
<br/>
<input type=submit />
</form>
<form id=myform1> <----Without Select Plugin
<select name=fruit>
<option value=>Year</option>
<option value=1>1955</option>
<option value=2>1956</option>
</select>
<br/>
<input type=submit />
</form>


JS:



$(document).ready(function () {
$('.selectpicker').selectpicker();


$('#myform').validate({ // initialize the plugin
ignore: [],
rules: {
year: {
required: true
}
},
errorPlacement: function(error, element) {
if (element.attr(name) == year) {
error.insertAfter(.bootstrap-select);
} else {
error.insertAfter(element);
}
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
});
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
debug: true,
success: valid
});
$( #myform1 ).validate({
rules: {
fruit: {
required: true
}
}
});

More From » jquery

 Answers
0

You need to check the validity on change



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


Demo: Fiddle


[#48606] Thursday, January 16, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;