Reputation: 156
Using: Jquery and jquery validate js
Error: If the textbox value and plceholder string is same then the required field validation is firing,
Code:
<form method="post" action="#">
<input type="text" name="name" placeholder="Your">
<input type="text" name="email" placeholder="[email protected]">
<button type="submit">Submit</button>
</form>
.
// Test if the submitted value is equal to our placeholder.
$.validator.addMethod('notPlaceholder', function(val, el) {
return ( val !== $(el).attr('placeholder') );
}, $.validator.messages.required);
$('form').validate({
rules: {
name: {
required: true,
notPlaceholder: true
},
email: {
required: true,
notPlaceholder: true,
email: true
}
},
// This is just for jsfiddle.
debug: true,
submitHandler: function(form) {
$.each( $(form).serializeArray(), function(i, f) {
$(form).append('<p>' +f.value+ '</p>');
});
}
});
Required: form should post
can anyone help me out?
Upvotes: 0
Views: 258
Reputation: 59272
I don't know what exactly you are doing, but you can do this:
$.validator.addMethod('notPlaceholder', function(val, el) {
return !(val !== $(el).attr('placeholder'));
}
That should work.
And for submitting the form, you can do:
$(form)[0].submit();
Upvotes: 0
Reputation: 3569
Try this code :
$.validator.addMethod('notPlaceholder', function(val, el) {
return ( val !== $(el).attr('placeholder') );
}, $.validator.messages.required);
$('form').validate({
rules: {
name: {
required: true,
},
email: {
required: true,
email: true
}
},
// This is just for jsfiddle.
debug: true,
submitHandler: function(form) {
$.each( $(form).serializeArray(), function(i, f) {
$(form).append('<p>' +f.value+ '</p>');
});
}
});
Upvotes: 0
Reputation: 13801
$('form').validate({
rules: {
name: {
required: true,
},
email: {
required: true,
email: true
}
},
// This is just for jsfiddle.
debug: true,
submitHandler: function(form) {
$.each( $(form).serializeArray(), function(i, f) {
$(form).append('<p>' +f.value+ '</p>');
});
}
});
Your jquery should looks like
Upvotes: 1