I'm trying to figure out the best way to validate a one page checkout. It contains :
- ship address
- billing address
- etc.
the Address class obvious contains First Name
, Last Name
, Street1
, Street2
, City
, State
, Zip
, Phone
etc.
Lets say the user clicks 'OK' before entering anything - then you end up with a dozen or more validation errors giving you a large block of red text that just looks ugly.
I'd like to validate the address as a single entity, and give an intelligent error - such as 'incomplete address', or more specific errors when appropriate. But I still want to be able to highlight each individual field that has a problem. I can't see an easy way to do this right now, because obviously the Html.ValidationSummary
helper will show every field.
So I want to show the summary as:
"Your shipping address is incomplete"
and highlight in red Zip
and City
.
I think I'd have to do a completely custom ValidationSummary, and maybe even a completely custom datastructure.
Do any validation frameworks make such a summary easier to do, where the summary should show an intelligent summary and not just every individual field error.
Edit: MVC 2 RC now supports model-level errors.
ValidationSummary now supports overloads where only model-level errors are displayed. This is useful if you are displaying validation messages inline next to each form field. Previously, these messages would be duplicated in the validation summary. With these new changes, you can have the summary display an overall validation message (ex. “There were errors in your form submission”) as well as a list of validation messages which don’t apply to a specific field.
Anybody got an actual sample of how to do this?