Skip to content

Commit

Permalink
fix(form-core): allow set default field meta (#424)
Browse files Browse the repository at this point in the history
Co-authored-by: João Pedro Magalhães <joaopsilvamagalhaes@gmail.com>
  • Loading branch information
joaom00 and João Pedro Magalhães authored Aug 31, 2023
1 parent bd1bd3d commit 6956d50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class FieldApi<TData, TFormData> {
meta: this.getMeta() ?? {
isValidating: false,
isTouched: false,
...this.options.defaultMeta,
...opts.defaultMeta,
},
},
{
Expand Down
26 changes: 18 additions & 8 deletions packages/form-core/src/tests/FieldApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})

expect(field.getMeta()).toEqual({
isTouched: false,
isValidating: false,
})
})

it('should allow to set default meta', () => {
const form = new FormApi()
const field = new FieldApi({
form,
name: 'name',
defaultMeta: { isTouched: true },
})

field.setValue('other')

expect(field.getValue()).toBe('other')
expect(field.getMeta()).toEqual({
isTouched: true,
isValidating: false,
})
})

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

0 comments on commit 6956d50

Please sign in to comment.