Monday, May 7, 2012
ASP.NET MVC: Adding aria-required attribute for required fields
http://blogs.msdn.com/b/stuartleeks/archive/2012/05/01/asp-net-mvc-adding-aria-required-attribute-for-required-fields.aspx
@{
var attributes = new RouteValueDictionary
{
{ "class", "text-box single-line"}
};
if (ViewContext.ViewData.ModelMetadata.IsRequired)
{
attributes.Add("aria-required", "true");
}
}
@Html.TextBox("", ViewContext.ViewData.TemplateInfo.FormattedModelValue, attributes)
@{
var attributes = new RouteValueDictionary
{
{ "class", "text-box single-line"}
};
if (ViewContext.ViewData.ModelMetadata.IsRequired)
{
attributes.Add("aria-required", "true");
}
}
@Html.TextBox("", ViewContext.ViewData.TemplateInfo.FormattedModelValue, attributes)
What is aria-required?
It is a HTML property to indicate if user input field is required. This property is for Accessible Rich Internet Applications
<input name="ariaexample" id="example" aria-required="true" aria-label="Test"/>
Reference:
http://www.w3.org/WAI/GL/WCAG20-TECHS/ARIA2.html
<input name="ariaexample" id="example" aria-required="true" aria-label="Test"/>
Reference:
http://www.w3.org/WAI/GL/WCAG20-TECHS/ARIA2.html
Subscribe to:
Posts (Atom)