mantine-form by mantinedev/skills
npx skills add https://github.com/mantinedev/skills --skill mantine-formconst form = useForm({
mode: 'controlled', // 对于大型表单,也可使用 'uncontrolled'
initialValues: {
email: '',
age: 0,
},
validate: {
email: isEmail('Invalid email'),
age: isInRange({ min: 18 }, 'Must be at least 18'),
},
});
<TextInput {...form.getInputProps('email')} label="Email" />
<NumberInput {...form.getInputProps('age')} label="Age" />
对于复选框,需要传递 { type: 'checkbox' }:
<Checkbox {...form.getInputProps('agreed', { type: 'checkbox' })} label="I agree" />
<form onSubmit={form.onSubmit((values) => console.log(values))}>
...
<Button type="submit">Submit</Button>
</form>
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
onSubmit 仅在验证通过时才会调用处理函数。要处理验证失败的情况:
form.onSubmit(
(values) => save(values),
(errors) => console.log('Validation failed', errors)
)
validate: {
name: isNotEmpty('Required'),
email: isEmail('Invalid email'),
password: hasLength({ min: 8 }, 'Min 8 chars'),
confirmPassword: matchesField('password', 'Passwords do not match'),
}
validate: (values) => ({
endDate: values.endDate < values.startDate ? 'End must be after start' : null,
})
validateInputOnChange: true, // 每次变更时验证所有字段
validateInputOnChange: ['email'], // 仅验证特定字段
validateInputOnBlur: true, // 在失去焦点时验证
| 模式 | 状态存储 | 重新渲染 | 输入属性 |
|---|---|---|---|
'controlled' (默认) | React 状态 | 每次变更时 | value + onChange |
'uncontrolled' | 引用 | 无 | defaultValue + onChange |
在非受控模式下,当你需要强制重新渲染某个输入控件时,使用 form.key('fieldPath') 作为 React 的 key 属性。
references/api.md — 完整 API:useForm 选项、完整的返回值、useField、createFormContext、createFormActions、所有内置验证器、键类型references/patterns.md — 代码示例:嵌套对象、数组字段、异步验证、跨组件表单上下文、transformValues、独立使用 useField每周安装量
108
代码仓库
GitHub 星标数
29
首次出现
2026年2月21日
安全审计
已安装于
cursor102
codex102
gemini-cli101
amp101
github-copilot101
opencode101
const form = useForm({
mode: 'controlled', // or 'uncontrolled' for large forms
initialValues: {
email: '',
age: 0,
},
validate: {
email: isEmail('Invalid email'),
age: isInRange({ min: 18 }, 'Must be at least 18'),
},
});
<TextInput {...form.getInputProps('email')} label="Email" />
<NumberInput {...form.getInputProps('age')} label="Age" />
For checkboxes pass { type: 'checkbox' }:
<Checkbox {...form.getInputProps('agreed', { type: 'checkbox' })} label="I agree" />
<form onSubmit={form.onSubmit((values) => console.log(values))}>
...
<Button type="submit">Submit</Button>
</form>
onSubmit only calls the handler when validation passes. To handle failures:
form.onSubmit(
(values) => save(values),
(errors) => console.log('Validation failed', errors)
)
validate: {
name: isNotEmpty('Required'),
email: isEmail('Invalid email'),
password: hasLength({ min: 8 }, 'Min 8 chars'),
confirmPassword: matchesField('password', 'Passwords do not match'),
}
validate: (values) => ({
endDate: values.endDate < values.startDate ? 'End must be after start' : null,
})
validateInputOnChange: true, // validate all fields on every change
validateInputOnChange: ['email'], // validate specific fields only
validateInputOnBlur: true, // validate on blur instead
| Mode | State storage | Re-renders | Input props |
|---|---|---|---|
'controlled' (default) | React state | On every change | value + onChange |
'uncontrolled' | Refs | None | defaultValue + onChange |
In uncontrolled mode, use form.key('fieldPath') as the React key prop when you need to force a re-render of an input.
references/api.md — Full API: useForm options, complete return value, useField, createFormContext, createFormActions, all built-in validators, key typesreferences/patterns.md — Code examples: nested objects, array fields, async validation, form context across components, transformValues, useField standaloneWeekly Installs
108
Repository
GitHub Stars
29
First Seen
Feb 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
cursor102
codex102
gemini-cli101
amp101
github-copilot101
opencode101
前端开发AI工具 | 5大专业能力构建生产级前端页面 | 设计工程与动效系统
699 周安装