Change validation options for a specific form

Consider formwhich are loaded via AJAX. After adding formto the document that I call

$.validator.unobtrusive.parse($form);

and customer check works like a charm. However, there are some scenarios when I need to change the verification settings, for example ignore, so I call

$form.validate({
    ignore: ''
});

$.validator.unobtrusive.parse($form); // and parse with new settings

In this case, unobtrusive client verification simply does not work. What could be the problem?

Edit

"Doesn't work" means $form.valid()always true.

+4
source share
2 answers

I found a solution:

$.validator.unobtrusive.parse($form); // parse the form
var validator = $.data($form[0], 'validator'); // get the form validator
validator.settings.ignore = ''; // change its settings
+3
source

I think this will help.

<div class="editor-field">
   @{ Html.EnableClientValidation(false); }
   @Html.TextBoxFor(m => m.BatchId, new { @class = "k-textbox" })
   @{ Html.EnableClientValidation(true); }</div>
+1

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


All Articles