문제

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)?

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top