diff --git a/docs/src/pages/api/form.mdx b/docs/src/pages/api/form.mdx index 1d013a6bc..438f877e2 100644 --- a/docs/src/pages/api/form.mdx +++ b/docs/src/pages/api/form.mdx @@ -140,6 +140,25 @@ Any fields without error messages will not be included in the object. So you can +`errorBag: Record` + + + +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 + + + `isSubmitting: boolean` diff --git a/docs/src/pages/api/use-form.mdx b/docs/src/pages/api/use-form.mdx index 43c6b89df..59aa47fa7 100644 --- a/docs/src/pages/api/use-form.mdx +++ b/docs/src/pages/api/use-form.mdx @@ -184,6 +184,7 @@ type useForm = (opts?: FormOptions) => { values: TValues; // current form values submitCount: Ref; // the number of submission attempts errors: ComputedRef>; // first error message for each field + errorBag: ComputedRef>>; // all error messages for each field meta: ComputedRef>; // aggregate of the field's meta information isSubmitting: Ref; // if the form submission function is being run setFieldValue(field: T, value: TValues[T]): void; // Sets a field value @@ -290,11 +291,25 @@ const { errors } = useForm(); errors.value; // access the errors value ``` + + +`errorBag: Ref>` + + + +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" } ```