Skip to content

Commit

Permalink
fix(form-core): allow set default field meta
Browse files Browse the repository at this point in the history
  • Loading branch information
João Pedro Magalhães committed Aug 31, 2023
1 parent 74a1dab commit 58ae4c8
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 58ae4c8

Please sign in to comment.