0

i am stuck in a situation where i am not able to apply validation when the contents are loaded dynamically through jquery ajax call...

I found this solution everywhere but dont know how to use where to write this code??

$('form').removeData("validator");
$('form').removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse('form');

MY CODE is HERE in my previous Question

1
  • please somebody help yaar Commented Jun 15, 2013 at 11:16

1 Answer 1

2

I do realise this is a old question. But it might be useful to someone who comes here in the future.

This is as simple as to run the above code after a successful ajax request.

$.ajax({
    url: editPageUrl,
    contentType: 'application/html; charset=utf-8',
    type: 'GET',
    dataType: 'html',
    data: { id: taskId },
    cache: false,
    success: function (data) {
        var taskBody = $('#task-body');
        $(taskBody).html(data);
        var $form = $(taskBody).find('form');
        $form.removeData("validator");
        $form.removeData("unobtrusiveValidation");
        $.validator.unobtrusive.parse($form);
    }
});

When the ajax request finishes just reset the validation so it works. Doing that will add all the elements to jquery validation and trigger the validation on a submit on the form inside #taskeditform-body

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.