Reputation: 1149
I just want to hide all the error message during and after typing the field (wrong input or empty field). And once the submit/button pressed then the message will all appear/visible.
The problem is... every time I typed wrong or I leave the text field empty it always shows the error message such "this fields is required", etc.
rules : {
"user.firstname" : {
required : true,
maxlength: 50,
},
messsages : {
required : "required",
maxlength: "the max-length is 50"
"
}
Upvotes: 2
Views: 2213
Reputation: 98728
As per online documentation, you need to use the onfocusout:
and onkeyup:
options.
Validate elements (except checkboxes/radio buttons) on blur. If nothing is entered, all rules are skipped, except when the field was already marked as invalid.
This disables onblur validation:
onfocusout: false
Validate elements on keyup. As long as the field is not marked as invalid, nothing happens. Otherwise, all rules are checked on each key up event.
This disables onkeyup validation:
onkeyup: false
And depending on if you have checkboxes and radio buttons, you may want to disable the onclick:
option as well.
Validate checkboxes and radio buttons on click.
This disables onclick validation:
onclick: false
Upvotes: 6
Reputation: 1171
Instead of $(document).ready(function(){} you can try using
$('input[type=submit]').click(function(event) {
// Do your validation, if it fails use event.preventDefault();
});
just give it a try let me know what happens...
Upvotes: -2