mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-10 12:27:45 +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() ?? {
|
meta: this.getMeta() ?? {
|
||||||
isValidating: false,
|
isValidating: false,
|
||||||
isTouched: false,
|
isTouched: false,
|
||||||
...this.options.defaultMeta,
|
...opts.defaultMeta,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user