Reputation: 473
I have a button that triggers the jquery validation plugin. The problem is that it always returns true, unless the fields are empty. It ignores the rules that are parsed.
DEMO http://jsfiddle.net/sw87W/835/
$(document).ready(function() {
$('#myForm').validate({
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
}
});
$('#validateForm').click(function() {
var isValid = $("#myForm").valid();
alert(isValid);
});
});
In fact you can delete my validate()
function and the same behaviour is present.
DEMO http://jsfiddle.net/sw87W/836/
$(document).ready(function() {
$('#validateForm').click(function() {
var isValid = $("#myForm").valid();
alert(isValid);
});
});
This question has been asked before, but doesn't answer my question:
jquery validate - remote always returns true
jQuery Validation always returns true
Upvotes: 1
Views: 243
Reputation: 1099
It worked when you add the rules sub object:
$(document).ready(function() {
$('#myForm').validate({
rules:{
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
}
}
});
$('#validateForm').click(function() {
var isValid = $("#myForm").valid();
alert(isValid);
});
});
Upvotes: 5