Skip to content

Commit 4c9bfd9

Browse files
committed
docs: added error bag to docs
1 parent 371744e commit 4c9bfd9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

docs/src/pages/api/form.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ Any fields without error messages will not be included in the object. So you can
140140

141141
<CodeTitle level="4">
142142

143+
`errorBag: Record<string, string>`
144+
145+
</CodeTitle>
146+
147+
An object that maps field names to all of their error messages.
148+
149+
Here is an example of its shape:
150+
151+
```js
152+
{
153+
email: ["this field is required", "this field must be a valid email"],
154+
password: "too short"
155+
}
156+
```
157+
158+
Any fields without error messages will not be included in the object. So be careful when accessing the errors array for each field
159+
160+
<CodeTitle level="4">
161+
143162
`isSubmitting: boolean`
144163

145164
</CodeTitle>

docs/src/pages/api/use-form.mdx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ type useForm = (opts?: FormOptions) => {
184184
values: TValues; // current form values
185185
submitCount: Ref<number>; // the number of submission attempts
186186
errors: ComputedRef<FormErrors<TValues>>; // first error message for each field
187+
errorBag: ComputedRef<Partial<Record<string, string[]>>>; // all error messages for each field
187188
meta: ComputedRef<FormMeta<TValues>>; // aggregate of the field's meta information
188189
isSubmitting: Ref<boolean>; // if the form submission function is being run
189190
setFieldValue<T extends keyof TValues>(field: T, value: TValues[T]): void; // Sets a field value
@@ -290,11 +291,25 @@ const { errors } = useForm();
290291
errors.value; // access the errors value
291292
```
292293

294+
<CodeTitle level="4">
295+
296+
`errorBag: Ref<Record<string, string>>`
297+
298+
</CodeTitle>
299+
300+
An object that maps field names to all of their error messages.
301+
302+
```js
303+
const { errorBag } = useForm();
304+
305+
errorBag.value.email; // email field errors
306+
```
307+
293308
Here is an example of its shape:
294309

295310
```js
296311
{
297-
email: "this field must be a valid email",
312+
email: ["this field is required", "this field must be a valid email"],
298313
password: "too short"
299314
}
300315
```

0 commit comments

Comments
 (0)