Question

I have a "list of clients" page with an "add" button that pops up a bootstrap modal, allowing the user to enter details of a new client. This uses the unobtrusive jQuery validation that comes pre-configured with an MVC(5) project.

I've got this to work, except for one case: if validation errors are shown and the user cancels the modal, then later clicks the "add" button again, the form fields are cleared, but the validation messages remain.

Is there an easy way (or rather what is the easy way, since I'm sure there will be one) to clear the "old" error messages when the modal is shown (in the .on('show.bs.modal', ... event)?

Was it helpful?

Solution

I forgot the actual code but it was something like -

var form = $("form") //use more specific selector if you like
form.removeData("validator").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse(form);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top