From 58ae4c829918a6dbb24ebaf3045387d5dd7ca43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Magalh=C3=A3es?= Date: Thu, 31 Aug 2023 18:47:22 -0300 Subject: [PATCH] fix(form-core): allow set default field meta --- packages/form-core/src/FieldApi.ts | 2 +- packages/form-core/src/tests/FieldApi.spec.ts | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/form-core/src/FieldApi.ts b/packages/form-core/src/FieldApi.ts index bf7e65ff9..2484adc4d 100644 --- a/packages/form-core/src/FieldApi.ts +++ b/packages/form-core/src/FieldApi.ts @@ -132,7 +132,7 @@ export class FieldApi { meta: this.getMeta() ?? { isValidating: false, isTouched: false, - ...this.options.defaultMeta, + ...opts.defaultMeta, }, }, { diff --git a/packages/form-core/src/tests/FieldApi.spec.ts b/packages/form-core/src/tests/FieldApi.spec.ts index d65186649..00b88a046 100644 --- a/packages/form-core/src/tests/FieldApi.spec.ts +++ b/packages/form-core/src/tests/FieldApi.spec.ts @@ -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', () => {