diff --git a/docs/reference/classes/fieldapi.md b/docs/reference/classes/fieldapi.md index ee7290043..0101142a5 100644 --- a/docs/reference/classes/fieldapi.md +++ b/docs/reference/classes/fieldapi.md @@ -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:673](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L673) *** @@ -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:662](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L662) *** @@ -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:644](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L644) *** @@ -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:1025](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1025) *** @@ -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:1018](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1018) *** @@ -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:686](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L686) *** @@ -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:716](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L716) *** @@ -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:678](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L678) *** @@ -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:704](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L704) *** @@ -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:695](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L695) *** @@ -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:1045](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1045) *** @@ -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:667](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L667) *** @@ -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:651](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L651) *** @@ -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:710](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L710) *** @@ -575,4 +575,4 @@ Validates the field value. #### 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:990](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L990) diff --git a/packages/form-core/src/FieldApi.ts b/packages/form-core/src/FieldApi.ts index 810869b7f..ddb7c993c 100644 --- a/packages/form-core/src/FieldApi.ts +++ b/packages/form-core/src/FieldApi.ts @@ -634,6 +634,7 @@ export class FieldApi< } this.options = opts as never + this.name = opts.name } /** diff --git a/packages/react-form/tests/useField.test.tsx b/packages/react-form/tests/useField.test.tsx index 651537346..80cce9c7b 100644 --- a/packages/react-form/tests/useField.test.tsx +++ b/packages/react-form/tests/useField.test.tsx @@ -239,6 +239,95 @@ describe('useField', () => { expect(queryByText(onBlurError)).toBeInTheDocument() }) + it('should properly update conditionally rendered fields', async () => { + type FormValues = { + firstField: string + secondField: string + showFirstField: boolean + } + + function Comp() { + const form = useForm({ + defaultValues: { + firstField: '', + secondField: '', + showFirstField: true, + } as FormValues, + }) + + return ( + <> +