[英]Using “required” on an <input> isn't accessible. Is there an easy way to make it accessible (JS) or do I have to abandon it?
My form has several input fields (email, first name, last name, etc.) that all use the "required" property. 我的表单有几个输入字段(电子邮件,名字,姓氏等),全部使用“ required”属性。
<input required></input>
This causes a nice universal error message to display in each browser, and lets the browser validate the inputs for me. 这会在每个浏览器中显示一个不错的通用错误消息,并让浏览器为我验证输入。
However, according to Accessible360, screen readers can't read those error messages. 但是,根据Accessible360,屏幕阅读器无法读取这些错误消息。
Is there a way to fix this that doesn't involve adding a bunch of extra tags, attributes, aria attributes, text, and Javascript? 有没有一种方法可以解决此问题,而无需添加大量额外的标签,属性,aria属性,文本和Javascript? Maybe just a little Javascript that will convert those in-browser errors into alerts? 也许只是一个Javascript会将浏览器内的错误转换为警报? I'm trying to keep my code clean. 我正在尝试保持代码清洁。
Thanks, I appreciate your help. 谢谢,谢谢您的帮助。
The problem is not the presence of the required
attribute which should be encouraged. 问题不在于应鼓励的required
属性的存在。 Back in 2012, Using the required attribute to indicate a required input field has been added a note about screenreader support. 早在2012年,就添加了关于屏幕阅读器支持的注释,即使用required属性指示必填字段 。 That was 7 years ago, and now the support is good with recent screenreaders. 那是7年前的事,现在,最近的屏幕阅读器提供了很好的支持。
Now the problem is that you must have a visual indication about required fields: H90: Indicating required form controls using label or legend and that you must indicate fields with errors G83: Providing text descriptions to identify required fields that were not completed 现在的问题是,您必须具有关于必填字段的直观指示: H90:使用标签或图例指示必填表单控件 ,并且必须指示带有错误的字段G83:提供文本描述以标识未完成的必填字段
The Paciello group has a good up-to-date page about that subject : Required attribute requirements which provide more informations about screenreader / browser support (" with the exception of using TalkBack with Firefox and Chrome on Android. ") and using aria-invalid
or aria-describedby
if a field has errors. Paciello组在该主题上有一个很好的最新页面: 必需的属性要求 ,它提供有关屏幕阅读器/浏览器支持的更多信息(“ ,但在Android上使用Firefox和Chrome使用TalkBack除外。 ”)以及使用aria-invalid
或用aria-describedby
如果字段有错误。
I imagine you can use jQuery to dynamically add the tags you need to all inputs with required. 我想您可以使用jQuery将所需的标签动态添加到具有所需的所有输入中。 For the required before HTML5 I think it's aria-required... 对于HTML5之前的必需文件,我认为它是aria必需的...
$(':input[required]').prop('aria-required',true);
According to Mozilla with aria-required screen readers should announce the field as required. Mozilla认为 ,必须使用咏叹调的屏幕阅读器应按要求宣布该字段。
For an alert you can have a script checking if all required inputs have a value onSubmit. 对于警报,您可以使用脚本检查是否所有必需的输入都具有onSubmit值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.