4

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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Doh, It's that simple! Think where I was going wrong was that I was searching for ASP.NET MVC client side validation not jquery validation. Many thanks.
Oh, Hell, I could have done with this before I wrote my own binder. <bg>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.