form-validation
它能做什么
这项技能检查表单验证,确保错误信息与正确的字段相连。适用于构建带有必填或需勾选输入项的表单的开发者。
适用场景
- ✓当表单显示的错误是屏幕阅读器用户找不到的时候。
- ✓当必填字段没有为辅助工具做标记的时候。
- ✓当错误只显示红色边框而没有任何提示信息的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/form-validation/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请让我表单中的错误提示对屏幕阅读器用户来说清晰明了。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查错误文字是否与每个字段相连,以及无效状态是否有标记。它会建议使用行内提示、必填标记,以及为分组选项使用 fieldset。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Validate forms accessibly
Inaccessible form validation leaves screen reader users unable to understand what went wrong and how to fix it, causing frustration and form abandonment.
Quick Reference
- Associate error messages with fields using aria-describedby
- Use aria-invalid to indicate validation state
- Mark required fields programmatically with
requiredoraria-required - Provide inline error messages near the field
- Don't rely solely on color to indicate errors
- Keep help text and error text linked to the field throughout validation
Check
Verify forms have client-side validation with accessible error messages linked to form fields via aria-describedby. Do not flag React forms just because they omit method or action when onSubmit clearly handles submission client-side. Confirm required fields are exposed programmatically and grouped controls use fieldset and legend.
Fix
Implement validation with clear error messages, aria-invalid states, and aria-describedby references to error text. For client-handled forms, improve validation semantics without forcing server-post patterns that the component is not using. Add required or aria-required where appropriate and use <fieldset> with <legend> for grouped choices.
Explain
Explain how accessible form validation improves user experience and ensures all users can understand and correct errors.
Code Review
Review templates, server-rendered HTML, and shared components that output markup related to Validate forms accessibly. Flag exact elements, attributes, and routes where the rendered HTML violates the rule. Check that help text and error text are both included in aria-describedby and that required state is exposed in markup, not only in visual styling.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/html/form-validation
常见问题
aria-describedby 有什么作用?
它将字段与其错误或帮助文字相连,使屏幕阅读器在读取字段时一并读出该信息。
只用颜色表示错误可以吗?
不可以。这项技能指出,不应只依靠颜色来显示错误。
它对 React 表单的判断方式相同吗?
这项技能指出,如果 React 表单通过代码处理提交,就不应仅因缺少 method 或 action 而标记它们。
详情
作者的原始描述
Use when reviewing templates, rendered HTML, or shared components related to Validate forms accessibly. Validate the final browser-facing markup, not just the source framework abstraction. Distinguish between browser-posted forms and client-handled React forms so you do not over-report missing `method` or `action` as accessibility defects.
热度
- GitHub 星标
- 75k
- 排名
- #2859
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。