fix(form-core): allow set default field meta (#424)

Co-authored-by: João Pedro Magalhães <joaopsilvamagalhaes@gmail.com>
This commit is contained in:
João Pedro Magalhães
2023-08-31 19:28:25 -03:00
committed by GitHub
parent bd1bd3d0d4
commit 6956d5085a
2 changed files with 20 additions and 10 deletions

View File

@@ -132,7 +132,7 @@ export class FieldApi<TData, TFormData> {
meta: this.getMeta() ?? { meta: this.getMeta() ?? {
isValidating: false, isValidating: false,
isTouched: false, isTouched: false,
...this.options.defaultMeta, ...opts.defaultMeta,
}, },
}, },
{ {

View File

@@ -19,21 +19,31 @@ describe('field api', () => {
expect(field.getValue()).toBe('test') expect(field.getValue()).toBe('test')
}) })
it('should set a value correctly', () => { it('should get default meta', () => {
const form = new FormApi({ const form = new FormApi()
defaultValues: {
name: 'test',
},
})
const field = new FieldApi({ const field = new FieldApi({
form, form,
name: 'name', name: 'name',
}) })
field.setValue('other') expect(field.getMeta()).toEqual({
isTouched: false,
isValidating: false,
})
})
expect(field.getValue()).toBe('other') it('should allow to set default meta', () => {
const form = new FormApi()
const field = new FieldApi({
form,
name: 'name',
defaultMeta: { isTouched: true },
})
expect(field.getMeta()).toEqual({
isTouched: true,
isValidating: false,
})
}) })
it('should set a value correctly', () => { it('should set a value correctly', () => {