hwc-forms-validation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseForms & Validation
表单与验证
Implement form-centric Hotwire workflows with Turbo Frames and Stimulus.
使用Turbo Frames和Stimulus实现以表单为中心的Hotwire工作流。
Core Workflow
核心工作流
- Identify the form flow: create/edit, inline edit, typeahead, modal form, or external controls.
- Wrap the form interaction scope in a Turbo Frame when validation errors must rerender in place.
- Return for validation failures and
422for successful redirects.303 - Handle post-submit behavior with only when Turbo defaults are insufficient.
turbo:submit-end - Preserve user context during rerenders (focus/caret/selection).
- 识别表单流程:创建/编辑、内联编辑、输入联想、模态表单或外部控件。
- 当验证错误需要原地重新渲染时,将表单交互范围包裹在Turbo Frame中。
- 验证失败时返回状态码,成功重定向时返回
422状态码。303 - 仅当Turbo默认行为不足时,使用处理提交后的行为。
turbo:submit-end - 在重新渲染期间保留用户上下文(焦点/光标/选中内容)。
Guardrails
注意事项
- Keep one source of truth for input state; avoid duplicate controls across frame and non-frame DOM.
- Use the HTML attribute for controls rendered outside the target
formhierarchy.<form> - Avoid firing submit logic on every keystroke without debounce/throttle.
- Keep post-submit behavior explicit when form responses update only a frame.
- 保持输入状态的单一数据源;避免在Frame和非Frame DOM中重复控件。
- 对于在目标层级之外渲染的控件,使用HTML的
<form>属性。form - 若无防抖/节流处理,避免在每次按键时触发提交逻辑。
- 当表单响应仅更新一个Frame时,明确处理提交后的行为。
Load References Selectively
选择性加载参考文档
Open only the file needed for the current request.
- Inline editing:
references/2024-02-27-turbo-frames-inline-edit.md - Modal validation flows:
references/2024-05-21-turbo-frames-modals-validation.md - Typeahead search:
references/2023-11-07-turbo-frames-typeahead-search.md - Typeahead validation with focus handling:
references/2025-10-20-turbo-frames-typeahead-validation.md - External form controls in frames:
references/2026-02-03-turbo-frames-external-form.md - Stimulus action parameters for forms:
references/2024-01-16-stimulus-action-parameters.md
Use for the full catalog.
references/INDEX.md仅打开当前请求所需的文件。
- 内联编辑:
references/2024-02-27-turbo-frames-inline-edit.md - 模态验证流程:
references/2024-05-21-turbo-frames-modals-validation.md - 输入联想搜索:
references/2023-11-07-turbo-frames-typeahead-search.md - 带焦点处理的输入联想验证:
references/2025-10-20-turbo-frames-typeahead-validation.md - Frame中的外部表单控件:
references/2026-02-03-turbo-frames-external-form.md - 表单的Stimulus动作参数:
references/2024-01-16-stimulus-action-parameters.md
使用查看完整目录。
references/INDEX.mdEscalate to Neighbor Skills
关联技能指引
- Navigation/history/cache behavior: use
hwc-navigation-content - WebSocket or Turbo Stream push updates: use
hwc-realtime-streaming - Media upload/playback behavior: use
hwc-media-content - Generic UX polish (spinners/progress/transitions): use
hwc-ux-feedback - General Stimulus API design questions: use
hwc-stimulus-fundamentals
- 导航/历史记录/缓存行为:使用
hwc-navigation-content - WebSocket或Turbo Stream推送更新:使用
hwc-realtime-streaming - 媒体上传/播放行为:使用
hwc-media-content - 通用用户体验优化(加载动画/进度条/过渡效果):使用
hwc-ux-feedback - 通用Stimulus API设计问题:使用
hwc-stimulus-fundamentals