0

How can I get validation to work on a Bootstrap "remote" modal that contains a form?

jQuery validation does not automatically apply to forms that are loaded in a "remote" Bootstrap modal.

1 Answer 1

3

Since the form does not exist in the DOM we need to have the the validator reparse the newly added content. Fortunately Bootstrap has an event that fires after after modals are shown.

$(document).on("shown.bs.modal", function (e) {
    $.validator.unobtrusive.parse(document);
});

Note to use "shown" and not "show" for the event name.

You may want to limit the call to only remote modals by adding a class to the modal div like "remote-modal-form" if you have a mix of local and remote modals on a page.

$(".remote-modal-form").on("shown.bs.modal", function (e) {
    $.validator.unobtrusive.parse($(".remote-modal-form"));
});
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.