I have a very strange issue with the jQuery Validation plugin where it won't validate a select
that was pre-filled then modified.
You can look at the code here: http://jsfiddle.net/VwRJ8/1/
The code never fires the alert()
in the following lines:
$('#edit_loc_save').click(function() {
var foo = $('#add_new_loc_form').valid();
alert(foo);
});
You can check if the select is valid each time the value is changed:
Javascript
$('#myform').validate();
$('#myselectbox').on('change', function() {
$(this).valid();
});
Demo
Edit 1
Here is what is causing an error in your javascript, which is preventing the validate function to operate correctly:
new_loc_zip: {
required: true,
postalcode: true // This is not a correct setting in jquery validate
},
If you remove the postalcode: true
line, validate will call properly.
Demo
if you want to do the validation while changing the option, then try to handle the change event of the select option and trigger the validation programatically
Try something like this
$(document).ready(function() {
$('#myselectbox').change(function() {
$('#myform').validate({
rules: {
myselectbox: {required: true }
}
}).form();
});
});
See the fiddle : here
http://jsfiddle.net/YRAga/2/
$('#myform').validate({
rules: {
myselectbox: {
required: true
}
}
});
$("#myselectbox").change(function() {
$("#myform").submit();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With