views:

365

answers:

1

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  A: 

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

gmcalab
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.
Steve Temple
Oh, Hell, I could have done with this before I wrote my own binder. <bg>
griegs