anhpht06/frontend-skill-pack/06-form-validation

Claude Code and agent skill by anhpht06/frontend-skill-pack

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

Quản lý Form và Validation bằng React Hook Form và Zod.

Install

npx vskill@latest install anhpht06/frontend-skill-pack/06-form-validation

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as anhpht06/frontend-skill-pack/06-form-validation.

Form Management & Validation

Tài liệu này quy định cách xử lý form và kiểm tra tính hợp lệ của dữ liệu đầu vào.

1. Công Cụ Tiêu Chuẩn

  • Bắt buộc sử dụng react-hook-form cho mọi form có từ 2 field (trường dữ liệu) trở lên.
  • Sử dụng zod (hoặc yup) để khai báo Schema Validation.
  • Sử dụng @hookform/resolvers/zod để kết nối Schema với Form.

2. Tổ chức Schema (src/schemas/)

  • Mọi schema validation phải được tách riêng vào thư mục src/schemas/, tuyệt đối không viết schema trực tiếp bên trong UI component.
  • Điều này giúp tái sử dụng schema (ví dụ: dùng chung schema cho Frontend và Backend) và giữ component gọn gàng.

```typescript // src/schemas/auth.schema.ts import { z } from "zod";

export const loginSchema = z.object({ email: z.string().min(1, "Email không được để trống").email("Email không hợp lệ"), password: z.string().min(6, "Mật khẩu tối thiểu 6 ký tự"), });

// Tự động suy luận Type từ Schema export type LoginFormValues = z.infer<typeof loginSchema>; ```

3. Quy Tắc Gọi API khi Submit

  • Trong hàm onSubmit, KHÔNG gọi trực tiếp hàm API.
  • Luôn luôn gọi hàm mutate (hoặc mutateAsync) từ Custom Hook của TanStack Query đã khai báo ở tầng UI Logic.

```typescript // ❌ Sai: Gọi trực tiếp API const onSubmit = async (data: LoginFormValues) => { await userApi.login(data); }

// ✅ Đúng: Gọi qua Mutation Hook const loginMutation = useLoginMutation(); const onSubmit = (data: LoginFormValues) => { loginMutation.mutate(data); } ```

4. Xử Lý Lỗi (Error Messages)

  • Lấy chuỗi báo lỗi từ errors object của react-hook-form (vd: errors.email?.message).
  • Không hardcode chuỗi báo lỗi trực tiếp trong JSX. Chuỗi lỗi phải được định nghĩa từ bên trong Zod Schema.

5. Sử Dụng Controller Cho Component Phức Tạp

  • Đối với các input HTML gốc (<input>, <select>), có thể dùng hàm register(...).
  • Đối với các Custom Component (ví dụ: UI từ thư viện thứ 3, DatePicker, Select nâng cao), BẮT BUỘC dùng `<Controller />` hoặc useController để đảm bảo dữ liệu được đồng bộ chính xác với form state.
  • Không dùng `any` khi định nghĩa các props cho Form Component.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anhpht06/frontend-skill-pack/06-form-validation/badge)](https://verified-skill.com/skills/anhpht06/frontend-skill-pack/06-form-validation)

Something wrong with this skill or its page? Tell us.