2
votes

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

1
Could you show the Email editor template?Bahman

1 Answers

4
votes

I think you are getting this behaviour because you are using an older version of jQuery validate. The plugin since 1.9.0 handles keyup, focus in and focus out for input elements with HTML5 types including email. The standard template of an MVC3 application comes with jquery validate 1.8.0, which won't.

so your answers:

  1. jQuery validate versions < 1.9.0 doesn't handle keyup, focusin and focusout events for html input element types such as type=email

  2. Upgrade your jquery-validate.js - 1.9.0 or higher