jquery.validate.unobtrusive でクライアントサイドで動的に追加したフィールドをチェック
i am using jquery's unobtrusive validation plugin in with asp.net mvc. the problem is that all the fields that are rendered server side gets validated with this scheme but if i dynamically add a field in the form using javascript it is not validated despite adding html-5 data-* attributes to the field. can anyone guide me in right direction on how i can achieve this goal thanks
jquery - client side validation with dynamically added field - Stack Overflow
Simpler Answer I am using MVC 4 and JQuery 1.8, looks like the following piece of code is needed I have made it to a modular function which accepts the Jquery object of the newly added element
function fnValidateDynamicContent(element) { var currForm = element.closest("form"); currForm.removeData("validator"); currForm.removeData("unobtrusiveValidation"); $.validator.unobtrusive.parse(currForm); currForm.validate(); // This line is important and added for client side validation to trigger, without this it didn't fire client side errors. }say you have added a new table with id tblContacts, then include the below function in your js file and call it as
fnValidateDynamicContent("#tblContacts")
jquery - client side validation with dynamically added field - Stack Overflow
edited Jan 7 '14 at 14:34 Sundara Prabu
なんという力技w