I am using JQuery validate plugin to validate my form and I would like to add a delay of 500ms before an input is being validated because it causes the error label to appear and disappear really fast.
I would like to get an answer that is JQuery Validate plugin related and not just a JQuery one.
For example , when there is min length of 2 char, I would like it to have a delay of 500ms before showing the error label + red border.
(If in my snippet it doesn't work, try to submit the form when it has 3 chars and after that type 1 char.)
$(document).ready(function() {
$("#myForm").validate({
debug:true,
rules: {
userName: {
required: true,
minlength: 2
}
},
submitHandler: function(form)
{
alert("pass validation");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<form id="myForm">
<input type="text" name="userName" placeholder="enter your name" value=""</>
<input type="submit" name="submit" value="submit"/>
</form>
Keep in mind I have a form with many inputs so I need a generic solution, I tried adding a timeout inside the highlight and error placement, but that caused to an unexpected behavior to inputs with custom methods.