react-f0rm 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/devtools/index.cjs.js +1 -743
- package/dist/devtools/index.cjs.js.map +1 -1
- package/dist/devtools/index.mjs +1 -723
- package/dist/devtools/index.mjs.map +1 -1
- package/dist/form-CGRvih_c.cjs.js +2 -0
- package/dist/form-CGRvih_c.cjs.js.map +1 -0
- package/dist/form-CfBBPz6p.mjs +2 -0
- package/dist/form-CfBBPz6p.mjs.map +1 -0
- package/dist/{form-rTlcIiWH.d.ts → form-D9COEt0-.d.ts} +2 -2
- package/dist/index.cjs.js +1 -1804
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +23 -4
- package/dist/index.mjs +1 -1711
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +22 -12
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -2
- package/dist/index.umd.min.js.map +1 -1
- package/dist/resolvers/standard-schema.cjs.js +1 -89
- package/dist/resolvers/standard-schema.cjs.js.map +1 -1
- package/dist/resolvers/standard-schema.mjs +1 -85
- package/dist/resolvers/standard-schema.mjs.map +1 -1
- package/dist/resolvers/yup.cjs.js +1 -22
- package/dist/resolvers/yup.cjs.js.map +1 -1
- package/dist/resolvers/yup.d.ts +1 -1
- package/dist/resolvers/yup.mjs +1 -20
- package/dist/resolvers/yup.mjs.map +1 -1
- package/dist/resolvers/zod.cjs.js +1 -22
- package/dist/resolvers/zod.cjs.js.map +1 -1
- package/dist/resolvers/zod.d.ts +1 -1
- package/dist/resolvers/zod.mjs +1 -20
- package/dist/resolvers/zod.mjs.map +1 -1
- package/dist/{validate-CQX7BJOD.d.ts → validate-Cu43SqhV.d.ts} +1 -1
- package/package.json +6 -1
- package/dist/form-CXF5HwQG.mjs +0 -349
- package/dist/form-CXF5HwQG.mjs.map +0 -1
- package/dist/form-DbnzAKSM.cjs.js +0 -358
- package/dist/form-DbnzAKSM.cjs.js.map +0 -1
package/README.md
CHANGED
|
@@ -349,6 +349,39 @@ const form = createForm({
|
|
|
349
349
|
});
|
|
350
350
|
```
|
|
351
351
|
|
|
352
|
+
#### Per-field mode override
|
|
353
|
+
|
|
354
|
+
Sometimes one field deserves a different schedule than the rest of the form — a signup form that validates on submit, except the email field whose check should fire as soon as the user leaves the input. Any field can declare its own `mode`: it replaces the form-level `mode` for that field only, while every other field keeps the form's timing.
|
|
355
|
+
|
|
356
|
+
```jsx
|
|
357
|
+
import {Form, Field, useForm} from 'react-f0rm';
|
|
358
|
+
|
|
359
|
+
function Register() {
|
|
360
|
+
// Form default: validate on submit.
|
|
361
|
+
const form = useForm({initialValues: {email: '', bio: ''}});
|
|
362
|
+
|
|
363
|
+
return (
|
|
364
|
+
<Form form={form}>
|
|
365
|
+
{/* This field alone validates on blur... */}
|
|
366
|
+
<Field name="email" mode="onBlur" validate={checkEmail} />
|
|
367
|
+
{/* ...while every other field waits for submit. */}
|
|
368
|
+
<Field name="bio" />
|
|
369
|
+
</Form>
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
The same option exists on `useField` (and `Checkbox` / `Select`):
|
|
375
|
+
|
|
376
|
+
```jsx
|
|
377
|
+
const email = useField({name: 'email', mode: 'onBlur', validate: checkEmail});
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
- Accepted values are the same `ValidationMode` union as the form's `mode`; omit it and the field follows `form.mode` exactly as before.
|
|
381
|
+
- Precedence is per field: `field.mode ?? form.mode`. A field cannot change another field's timing, and declaring `mode: 'onSubmit'` opts a field out of an `'onChange'` form.
|
|
382
|
+
- `reValidateMode` stays form-level for every field: once a field has an error (after a failed submit, say), re-validation follows the form's `reValidateMode` regardless of the field's own `mode` — a `mode: 'onBlur'` field with the default `reValidateMode: 'onChange'` still re-validates on every keystroke while errored.
|
|
383
|
+
- Manual `trigger` and submit validation are unaffected — they always run the field's validators regardless of any mode.
|
|
384
|
+
|
|
352
385
|
### Triggering validation manually
|
|
353
386
|
|
|
354
387
|
`trigger` runs field validators on demand. Without a name it runs every registered validator; a single name — or an array of names — narrows it to those fields:
|
|
@@ -758,6 +791,14 @@ import {renderToString} from 'react-dom/server';
|
|
|
758
791
|
const html = renderToString(<ProfileForm initialValues={{name: 'ada', city: 'london'}} />);
|
|
759
792
|
```
|
|
760
793
|
|
|
794
|
+
## Migrating
|
|
795
|
+
|
|
796
|
+
Coming from another library? Step-by-step migration guides live in the docs site:
|
|
797
|
+
|
|
798
|
+
- [Migrating from Formik](docs-site/docs/migration/from-formik.md)
|
|
799
|
+
- [Migrating from React Hook Form](docs-site/docs/migration/from-react-hook-form.md)
|
|
800
|
+
- [Migrating from TanStack Form](docs-site/docs/migration/from-tanstack-form.md)
|
|
801
|
+
|
|
761
802
|
## Breaking changes in 0.2
|
|
762
803
|
|
|
763
804
|
v0.2 structures the error model (`FieldError`), changes unregister/reset/native-validation semantics, and more — see the [v0.1 → v0.2 migration guide](docs-site/docs/migration/v0.1-to-v0.2.md).
|