How to reinitialize unobtrusive jQuery validation?

I load a form with the proper attributes for jQuery through an AJAX call, the problem is that it loads after the document is ready, unobtrusive jQuery validation does not pick up the required validation. Can anyone tell me a method that I would use to reinitialize it?

+6
source share
2 answers

To analyze the validation attributes of a form after you return it to the page, you need to execute it: $.validator.unobtrusive.parse('#yourFormSelector')

In my application, I put this call into the ajaxComplete handler, so I no longer need to worry about that. I rewrite each form on the page, and it works fine during the production process for quite some time (even if there are several hundred forms on the page).

 $(document).ajaxComplete(function() { $.validator.unobtrusive.parse('form'); }); 
+25
source

You need to reinitialize it in the return result of which ajax method you are using, using the same call that you are currently using to initialize the validation

  $(selector).load( formUrl, function(){ /* form exists here, run code*/ }) 
0
source

Source: https://habr.com/ru/post/910270/


All Articles