mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-06 04:19:43 +00:00
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:
committed by
GitHub
parent
bd1bd3d0d4
commit
6956d5085a
@@ -132,7 +132,7 @@ export class FieldApi<TData, TFormData> {
|
||||
meta: this.getMeta() ?? {
|
||||
isValidating: false,
|
||||
isTouched: false,
|
||||
...this.options.defaultMeta,
|
||||
...opts.defaultMeta,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -19,21 +19,31 @@ describe('field api', () => {
|
||||
expect(field.getValue()).toBe('test')
|
||||
})
|
||||
|
||||
it('should set a value correctly', () => {
|
||||
const form = new FormApi({
|
||||
defaultValues: {
|
||||
name: 'test',
|
||||
},
|
||||
})
|
||||
|
||||
it('should get default meta', () => {
|
||||
const form = new FormApi()
|
||||
const field = new FieldApi({
|
||||
form,
|
||||
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', () => {
|
||||
|
||||
Reference in New Issue
Block a user