开发者

Hiding and showing fields still validates hidden fields with ASP.NET MVC 2 Client Side Validation

开发者 https://www.devze.com 2022-12-28 15:12 出处:网络
I\'ve got a form as part of an e-commerce checkout process which has a section for billing address which allows the user to use their delivery address or to fill in an address in the form. If the user

I've got a form as part of an e-commerce checkout process which has a section for billing address which allows the user to use their delivery address or to fill in an address in the form. If the user selects to use their delivery address I don't show the address fields.

I've added validation for all fields then on the server side I check which option was selected and remove any validation errors for fields that are now hidden. This works fine on the server site but I'd like to use MVC 2's client side validation and need some way of doing the same on the client side.

What I'd like is a way of getting the javascript validation to ignore any hidden fields. Is there a good way of doing this or is it a case of hacking the MicrosoftMvcJQueryValidation.js fi开发者_运维问答le?


jQuery validation ignore hidden's?

$("#myform").validate({
   ignore: ":hidden"
})

Elements can be considered hidden for several reasons:

  • They have a display value of none.
  • They are form elements with type="hidden".
  • Their width and height are explicitly set to 0.
  • An ancestor element is hidden, so the element is not shown on the page.

Source: here

0

精彩评论

暂无评论...
验证码 换一张
取 消