Jquery validate - field validation in pageload

I have an input field in my simple html form that I would like to mark as invalid (and the displayed error message) from the moment the page loads.

Is this possible with jquery validation plugin?

Otherwise, how can I hide the element when the plugin tries to check a specific input field?

0
jquery jquery-validate
source share
2 answers

I managed to solve the problem. This is due to the addition of the 'dummy' check item that appears when the page loads. As soon as the user enters a value in the corresponding field, the dummy element is hidden and the real one is displayed.

I used the highlight and unhighlight parameters for the validation method to achieve what I wanted.

$("#myform").validate({ highlight: function(element){ if($(element).hasClass("math")){ $(".temp").hide(); } }, unhighlight: function(element){ if($(element).hasClass("math")){ $(".temp").hide(); } } }); 

Perhaps this will help someone else in the future.

0
source share

I think you will need to have a form that you check in order to submit the page to load. Maybe something like this:

  $(document).ready(function() { $('form').validate(/* set all of your validator options here */); $('form').trigger('submit'); }); 
0
source share

All Articles