Question

Consider the form that are loaded via AJAX. After appending the form to the document I'm calling

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

and the client validation works like a charm. However there are some scenarios, when I need to change the validation settings, like ignore, so I call

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

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

In this case unobtrusive client validation just doesn't work. What could be the issue?

Edit

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

Was it helpful?

Solution

I found the solution:

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

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top