Search code examples
jqueryasp.net-mvcvalidationunobtrusive-validationfoolproof-validation

MVC Rebind Foolproof Validation


Hi I am loading a form and using unobtrusive clientside validation extended with the foolproof nuget package. This all works well but now I am trying to load parts of the form with ajax.

Once these parts have been loaded in using ajax, the validation isn't bound to the new fields.

For the normal validation, I am able to rebind it using

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

Is there a similar method for rebinding them foolproof validation?


Solution

  • foolproof adds client side validation in the same way that MVC's validation attributes do, by defining a rule to be added to jQuery validation using the $.validator.addMethod() and $.validator.unobtrusive.adapters.add() functions, so parsing the validator will also work for foolproof validation attributes.

    Note that before reparsing the validator, you should reset the validator to null

    var form = $('form');
    form.data('validator', null);
    $.validator.unobtrusive.parse(form);