跳到正文
Skillpedia
网站与界面(前端)75k · #2859

form-validation

它能做什么

这项技能检查表单验证,确保错误信息与正确的字段相连。适用于构建带有必填或需勾选输入项的表单的开发者。

适用场景

  • ✓当表单显示的错误是屏幕阅读器用户找不到的时候。
  • ✓当必填字段没有为辅助工具做标记的时候。
  • ✓当错误只显示红色边框而没有任何提示信息的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/form-validation/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/form-validation/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 required or aria-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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2859
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能