I have a mobile application I'm writing in ASP.Net MVC3 (using JQuery unobtrusive validate). As part of it, I am collecting name and email information from the users. My model includes fields like:
[Required] public String Name {get; set;}
[Required] public String Email {get; set;}
In my view, I have input element of the form:
@Html.EditorFor(m => m.Name);
@Html.EditorFor(m => m.Email, "Email");
where the String editor template and the Email editor template are identical, except the Email template explicitly sets the type attribute to "email".
When I initially submit the form without entering any data, I get client-side validations stating both fields are required. When I start typing in the Name field, the validation warning immediately goes away. When I start typing in the Email field, the validation remains.
I can then click on submit, and the form submits properly, despite the "The Email field is required." validation message remaining visible.
If I modify the Email editor template to set type="text" instead of type="email", the validation clears the way I expect it to (but mobile users won't get the email-specific keyboard).
Two questions: (1) Why is it behaving the way it is? (2) How can I get it to behave "properly" (i.e, the "required" validation going away when an email has been entered)?