We have an ASP.NET MVC 5 web application. We do regular accessibility testing with JAWS in conjunction with Internet Explorer 11 (enterprise mandate) and Chrome. We keep running into problems with JAWS not reading off the validation messages associated with form fields when the user TABs into the field. We use FluentValidation and the standard HTML helpers to display form fields and validation messages (example below):
@Html.LabelFor(model => model.Email)
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email, null, new { role = "alert" })
A sample FluentValidation might query the database for the e-mail address in the form and show a message that "This e-mail has already been taken" which runs on the server side.
The resulting HTML sent back to the browser is:
<label for="Email">E-mail address:</label>
<input type="text" name="Email" id="Email" ...>
<span class="..." data-valmsg-for="Email" data-valmsg-replace="true" role="alert">
This e-mail has already been taken
</span>
Nothing is associating the validation message with the form field. I always thought the MVC framework made this connection automatically, but apparently it doesn't.
According to WebAIM, we should utilize the aria-describedby
attribute to associate form fields with inline validation errors, but to replumb the existing MVC5 framework to do that is quite the undertaking.
How can we get screen readers to announce inline validation messages when bringing focus to a form field generated by ASP.NET MVC5 without rewriting major HTML helpers?