Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return an array of errors from a single validator (custom & schema library) #1090

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/framework/angular/guides/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ Or use the `errorMap` property to access the specific error you're looking for:
#age="field"
>
<!-- ... -->
@if (age.api.state.meta.errorMap['onChange']) {
<em role="alert">{{ age.api.state.meta.errorMap['onChange'] }}</em>
@if (age.api.state.meta.errorMap['onChange']?.length) {
<em role="alert">{{ age.api.state.meta.errorMap['onChange'][0] }}</em>
}
</ng-container>
`,
Expand Down Expand Up @@ -219,10 +219,10 @@ Example:
<div>
<ng-container [tanstackField]="form" name="age" #age="field">
<!-- ... -->
@if (formErrorMap().onChange) {
@if (formErrorMap().onChange?.length) {
<div>
<em
>There was an error on the form: {{ formErrorMap().onChange }}</em
>There was an error on the form: {{ formErrorMap().onChange[0] }}</em
>
</div>
}
Expand Down
12 changes: 6 additions & 6 deletions docs/framework/react/guides/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ Or use the `errorMap` property to access the specific error you're looking for:
{(field) => (
<>
{/* ... */}
{field.state.meta.errorMap['onChange'] ? (
<em>{field.state.meta.errorMap['onChange']}</em>
{field.state.meta.errorMap['onChange']?.length ? (
<em>{field.state.meta.errorMap['onChange'][0]}</em>
) : null}
</>
)}
Expand Down Expand Up @@ -183,9 +183,9 @@ export default function App() {
return (
<div>
{/* ... */}
{formErrorMap.onChange ? (
{formErrorMap.onChange?.length ? (
<div>
<em>There was an error on the form: {formErrorMap.onChange}</em>
<em>There was an error on the form: {formErrorMap.onChange[0]}</em>
</div>
) : null}
{/* ... */}
Expand Down Expand Up @@ -251,9 +251,9 @@ export default function App() {
<form.Subscribe
selector={(state) => [state.errorMap]}
children={([errorMap]) =>
errorMap.onSubmit ? (
errorMap.onSubmit?.length ? (
<div>
<em>There was an error on the form: {errorMap.onSubmit}</em>
<em>There was an error on the form: {errorMap.onSubmit[0]}</em>
</div>
) : null
}
Expand Down
8 changes: 4 additions & 4 deletions docs/framework/solid/guides/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ Or use the `errorMap` property to access the specific error you're looking for:
{(field) => (
<>
{/* ... */}
{field().state.meta.errorMap['onChange'] ? (
<em>{field().state.meta.errorMap['onChange']}</em>
{field().state.meta.errorMap['onChange']?.length ? (
<em>{field().state.meta.errorMap['onChange'][0]}</em>
) : null}
</>
)}
Expand Down Expand Up @@ -185,9 +185,9 @@ export default function App() {
return (
<div>
{/* ... */}
{formErrorMap().onChange ? (
{formErrorMap().onChange?.length ? (
<div>
<em>There was an error on the form: {formErrorMap().onChange}</em>
<em>There was an error on the form: {formErrorMap().onChange[0]}</em>
</div>
) : null}
{/* ... */}
Expand Down
6 changes: 3 additions & 3 deletions docs/framework/vue/guides/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Or use the `errorMap` property to access the specific error you're looking for:
}">
<template v-slot="{ field }">
<!-- ... -->
<em role="alert" v-if="field.state.meta.errorMap['onChange']">{{ field.state.meta.errorMap['onChange'] }}</em>
<em role="alert" v-if="field.state.meta.errorMap['onChange']?.length">{{ field.state.meta.errorMap['onChange'][0] }}</em>
</template>
</form.Field>
<!-- ... -->
Expand Down Expand Up @@ -178,9 +178,9 @@ const formErrorMap = form.useStore((state) => state.errorMap)

<template>
<!-- ... -->
<div v-if="formErrorMap.onChange">
<div v-if="formErrorMap.onChange?.length">
<em role="alert">
There was an error on the form: {{formErrorMap.onChange }}
There was an error on the form: {{formErrorMap.onChange[0] }}
</em>
</div>
<!-- ... -->
Expand Down
52 changes: 26 additions & 26 deletions docs/reference/classes/fieldapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Initializes a new `FieldApi` instance.

#### Defined in

[packages/form-core/src/FieldApi.ts:477](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L477)
[packages/form-core/src/FieldApi.ts:478](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L478)

## Properties

Expand All @@ -61,7 +61,7 @@ A reference to the form API instance.

#### Defined in

[packages/form-core/src/FieldApi.ts:441](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L441)
[packages/form-core/src/FieldApi.ts:442](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L442)

***

Expand All @@ -75,7 +75,7 @@ The field name.

#### Defined in

[packages/form-core/src/FieldApi.ts:451](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L451)
[packages/form-core/src/FieldApi.ts:452](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L452)

***

Expand All @@ -89,7 +89,7 @@ The field options.

#### Defined in

[packages/form-core/src/FieldApi.ts:455](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L455)
[packages/form-core/src/FieldApi.ts:456](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L456)

***

Expand All @@ -103,7 +103,7 @@ The field state store.

#### Defined in

[packages/form-core/src/FieldApi.ts:465](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L465)
[packages/form-core/src/FieldApi.ts:466](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L466)

***

Expand All @@ -115,7 +115,7 @@ timeoutIds: Record<ValidationCause, null | Timeout>;

#### Defined in

[packages/form-core/src/FieldApi.ts:472](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L472)
[packages/form-core/src/FieldApi.ts:473](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L473)

## Accessors

Expand All @@ -135,7 +135,7 @@ The current field state.

#### Defined in

[packages/form-core/src/FieldApi.ts:469](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L469)
[packages/form-core/src/FieldApi.ts:470](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L470)

## Methods

Expand All @@ -153,7 +153,7 @@ Gets the field information object.

#### Defined in

[packages/form-core/src/FieldApi.ts:672](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L672)
[packages/form-core/src/FieldApi.ts:676](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L676)

***

Expand All @@ -169,7 +169,7 @@ getMeta(): FieldMeta

#### Defined in

[packages/form-core/src/FieldApi.ts:661](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L661)
[packages/form-core/src/FieldApi.ts:665](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L665)

***

Expand All @@ -191,7 +191,7 @@ Use `field.state.value` instead.

#### Defined in

[packages/form-core/src/FieldApi.ts:643](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L643)
[packages/form-core/src/FieldApi.ts:647](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L647)

***

Expand All @@ -209,7 +209,7 @@ Handles the blur event.

#### Defined in

[packages/form-core/src/FieldApi.ts:1024](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1024)
[packages/form-core/src/FieldApi.ts:1030](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1030)

***

Expand All @@ -233,7 +233,7 @@ Handles the change event.

#### Defined in

[packages/form-core/src/FieldApi.ts:1017](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1017)
[packages/form-core/src/FieldApi.ts:1023](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1023)

***

Expand Down Expand Up @@ -268,7 +268,7 @@ Inserts a value at the specified index, shifting the subsequent values to the ri

#### Defined in

[packages/form-core/src/FieldApi.ts:685](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L685)
[packages/form-core/src/FieldApi.ts:689](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L689)

***

Expand All @@ -290,7 +290,7 @@ Mounts the field instance to the form.

#### Defined in

[packages/form-core/src/FieldApi.ts:567](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L567)
[packages/form-core/src/FieldApi.ts:568](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L568)

***

Expand Down Expand Up @@ -325,7 +325,7 @@ Moves the value at the first specified index to the second specified index.

#### Defined in

[packages/form-core/src/FieldApi.ts:715](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L715)
[packages/form-core/src/FieldApi.ts:719](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L719)

***

Expand Down Expand Up @@ -353,7 +353,7 @@ Pushes a new value to the field.

#### Defined in

[packages/form-core/src/FieldApi.ts:677](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L677)
[packages/form-core/src/FieldApi.ts:681](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L681)

***

Expand Down Expand Up @@ -381,7 +381,7 @@ Removes a value at the specified index.

#### Defined in

[packages/form-core/src/FieldApi.ts:703](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L703)
[packages/form-core/src/FieldApi.ts:707](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L707)

***

Expand Down Expand Up @@ -416,7 +416,7 @@ Replaces a value at the specified index.

#### Defined in

[packages/form-core/src/FieldApi.ts:694](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L694)
[packages/form-core/src/FieldApi.ts:698](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L698)

***

Expand All @@ -440,7 +440,7 @@ Updates the field's errorMap

#### Defined in

[packages/form-core/src/FieldApi.ts:1044](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1044)
[packages/form-core/src/FieldApi.ts:1050](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1050)

***

Expand All @@ -464,7 +464,7 @@ Sets the field metadata.

#### Defined in

[packages/form-core/src/FieldApi.ts:666](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L666)
[packages/form-core/src/FieldApi.ts:670](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L670)

***

Expand Down Expand Up @@ -492,7 +492,7 @@ Sets the field value and run the `change` validator.

#### Defined in

[packages/form-core/src/FieldApi.ts:650](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L650)
[packages/form-core/src/FieldApi.ts:654](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L654)

***

Expand Down Expand Up @@ -527,7 +527,7 @@ Swaps the values at the specified indices.

#### Defined in

[packages/form-core/src/FieldApi.ts:709](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L709)
[packages/form-core/src/FieldApi.ts:713](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L713)

***

Expand All @@ -551,14 +551,14 @@ Updates the field instance with new options.

#### Defined in

[packages/form-core/src/FieldApi.ts:606](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L606)
[packages/form-core/src/FieldApi.ts:610](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L610)

***

### validate()

```ts
validate(cause): ValidationError[] | Promise<ValidationError[]>
validate(cause): string[] | Promise<string[]>
```

Validates the field value.
Expand All @@ -571,8 +571,8 @@ Validates the field value.

#### Returns

[`ValidationError`](../type-aliases/validationerror.md)[] \| `Promise`\<[`ValidationError`](../type-aliases/validationerror.md)[]\>
`string`[] \| `Promise`\<`string`[]\>

#### Defined in

[packages/form-core/src/FieldApi.ts:989](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L989)
[packages/form-core/src/FieldApi.ts:995](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L995)
Loading
Loading