Hiding and showing fields still validates hidden fields using ASP.NET MVC 2 client-side validation

I have a form as part of an e-commerce verification process that has a section for a billing address that allows the user to use their delivery address or fill in the address on the form. If the user chooses to use his delivery address, I do not show the address field.

I added validation for all fields, and then on the server side. I check which option was selected and remove all validation errors for the fields that are now hidden. This works fine on the server site, but I would like to use MVC 2 client side validation and you need a way to do the same on the client side.

I would like the javascript validation to ignore any hidden fields. Is there a good way to do this or is it a case of hacking the MicrosoftMvcJQueryValidation.js file?

+4
source share
1 answer

JQuery validation ignores hidden?

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

Elements can be considered hidden for several reasons:

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

Source: here

+3
source

Source: https://habr.com/ru/post/1308185/


All Articles