MVC Adding methods into jquery.validate.unobtrusive.js

前端 未结 3 1172
醉酒成梦
醉酒成梦 2021-02-03 10:17

I recently had a question on getting checkbox validation working on the client side within a MVC project. This question was successfully answered, but raised another query.

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 10:46

    Sniffer,

    The more I look at this, the more I shake my head (at myself).

    Upon further review, Darin's method will work, provided that you add one line to his page script:

    
    

    Whenever you make a change (such as adding a new adapter), you must re-parse the unobtrusive validation attributes. Since the last action in jquery.validate.unobtrusive.js is the parsing of the attributes, and the adapter is being added after the parsing, re-parsing solves this issue.

    counsellorben

    P.S. This solves your issue, but still leaves unresolved the issue of how to add other custom validators which do not use built-in methods from jquery.validate.js without modifying jquery.validate.unobtrusive.js.

    P.P.S. I found the answer for adding custom validation methods. In order to add custom validation mmethods without modifying jquery.validate.unobtrusive.js, you need to "borrow" some of its code to add to your page script. Adding a custom method then looks like the following:

    
    

提交回复
热议问题