Skip to content

Commit 6956d50

Browse files
joaom00João Pedro Magalhães
andauthored
fix(form-core): allow set default field meta (#424)
Co-authored-by: João Pedro Magalhães <[email protected]>
1 parent bd1bd3d commit 6956d50

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

packages/form-core/src/FieldApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class FieldApi<TData, TFormData> {
132132
meta: this.getMeta() ?? {
133133
isValidating: false,
134134
isTouched: false,
135-
...this.options.defaultMeta,
135+
...opts.defaultMeta,
136136
},
137137
},
138138
{

packages/form-core/src/tests/FieldApi.spec.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,31 @@ describe('field api', () => {
1919
expect(field.getValue()).toBe('test')
2020
})
2121

22-
it('should set a value correctly', () => {
23-
const form = new FormApi({
24-
defaultValues: {
25-
name: 'test',
26-
},
22+
it('should get default meta', () => {
23+
const form = new FormApi()
24+
const field = new FieldApi({
25+
form,
26+
name: 'name',
2727
})
2828

29+
expect(field.getMeta()).toEqual({
30+
isTouched: false,
31+
isValidating: false,
32+
})
33+
})
34+
35+
it('should allow to set default meta', () => {
36+
const form = new FormApi()
2937
const field = new FieldApi({
3038
form,
3139
name: 'name',
40+
defaultMeta: { isTouched: true },
3241
})
3342

34-
field.setValue('other')
35-
36-
expect(field.getValue()).toBe('other')
43+
expect(field.getMeta()).toEqual({
44+
isTouched: true,
45+
isValidating: false,
46+
})
3747
})
3848

3949
it('should set a value correctly', () => {

0 commit comments

Comments
 (0)