Skip to content

Commit

Permalink
docs: added error bag to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Mar 12, 2023
1 parent 371744e commit 4c9bfd9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
19 changes: 19 additions & 0 deletions docs/src/pages/api/form.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ Any fields without error messages will not be included in the object. So you can

<CodeTitle level="4">

`errorBag: Record<string, string>`

</CodeTitle>

An object that maps field names to all of their error messages.

Here is an example of its shape:

```js
{
email: ["this field is required", "this field must be a valid email"],
password: "too short"
}
```

Any fields without error messages will not be included in the object. So be careful when accessing the errors array for each field

<CodeTitle level="4">

`isSubmitting: boolean`

</CodeTitle>
Expand Down
17 changes: 16 additions & 1 deletion docs/src/pages/api/use-form.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ type useForm = (opts?: FormOptions) => {
values: TValues; // current form values
submitCount: Ref<number>; // the number of submission attempts
errors: ComputedRef<FormErrors<TValues>>; // first error message for each field
errorBag: ComputedRef<Partial<Record<string, string[]>>>; // all error messages for each field
meta: ComputedRef<FormMeta<TValues>>; // aggregate of the field's meta information
isSubmitting: Ref<boolean>; // if the form submission function is being run
setFieldValue<T extends keyof TValues>(field: T, value: TValues[T]): void; // Sets a field value
Expand Down Expand Up @@ -290,11 +291,25 @@ const { errors } = useForm();
errors.value; // access the errors value
```

<CodeTitle level="4">

`errorBag: Ref<Record<string, string>>`

</CodeTitle>

An object that maps field names to all of their error messages.

```js
const { errorBag } = useForm();

errorBag.value.email; // email field errors
```

Here is an example of its shape:

```js
{
email: "this field must be a valid email",
email: ["this field is required", "this field must be a valid email"],
password: "too short"
}
```
Expand Down

0 comments on commit 4c9bfd9

Please sign in to comment.