From 7f20503318df79695eb471afbcade27c426ca836 Mon Sep 17 00:00:00 2001 From: Claudio Savino Date: Thu, 30 Mar 2023 12:29:51 +0200 Subject: [PATCH] fix: ref computed, allow set ref ref computed, allow set ref --- CHANGELOG.md | 6 +++++- src/Base.ts | 2 +- src/props.ts | 11 ++++++----- src/utils.ts | 6 +++--- tests/data/forms/nested/form.v.ts | 3 +++ tests/nested.hooks.ts | 6 ++++++ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7846112..0718c829 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -# 5.6.0 (next) +# 5.7.1 (next) + +- fix: allow `ref` prop on `set()` +- fix: `ref` computed accessible (before was accessed by $ref) +# 5.7.0 (next) - Introduced `ref` Field prop. (handle React Refs); - `ref` is auto-binded with the input when using `bind()` or can be defined/changed with `set()` diff --git a/src/Base.ts b/src/Base.ts index 7926221d..f41e8fa2 100755 --- a/src/Base.ts +++ b/src/Base.ts @@ -453,7 +453,7 @@ export default class Base implements BaseInterface { get(prop: any = null, strict: boolean = true): any { if (_.isNil(prop)) { return this.deepGet( - [...props.computed, ...props.field, ...props.validation], + [...props.computed, ...props.editable, ...props.validation], this.fields ); } diff --git a/src/props.ts b/src/props.ts index 1c7f8123..95aab9ad 100755 --- a/src/props.ts +++ b/src/props.ts @@ -1,20 +1,20 @@ import { FieldPropsEnum } from "./models/FieldProps"; export interface PropsGroupsInterface { - field: FieldPropsEnum[]; - handlers: FieldPropsEnum[]; - computed: FieldPropsEnum[]; - separated: string[]; + editable: string[]; + handlers: string[]; + computed: string[]; functions: string[]; validation: string[]; exceptions: string[]; + separated: string[]; types: { [index: string]: "some" | "every"; }; } export const props: PropsGroupsInterface = { - field: [ + editable: [ FieldPropsEnum.type, FieldPropsEnum.value, FieldPropsEnum.initial, @@ -31,6 +31,7 @@ export const props: PropsGroupsInterface = { FieldPropsEnum.deleted, FieldPropsEnum.disabled, FieldPropsEnum.autoFocus, + FieldPropsEnum.ref, ], handlers: [ FieldPropsEnum.onChange, diff --git a/src/utils.ts b/src/utils.ts index c09c99e7..b0439bb5 100755 --- a/src/utils.ts +++ b/src/utils.ts @@ -44,7 +44,7 @@ const hasProps = ($type: any, $data: any) => { break; case "field": $props = [ - ...props.field, + ...props.editable, ...props.validation, ...props.functions, ...props.handlers, @@ -54,7 +54,7 @@ const hasProps = ($type: any, $data: any) => { $props = [ FieldPropsEnum.id, ...props.computed, - ...props.field, + ...props.editable, ...props.validation, ...props.functions, ...props.handlers, @@ -119,7 +119,7 @@ const allowNested = (field: any, strictProps: boolean): boolean => !_.isDate(field) && !_.has(field, FieldPropsEnum.fields) && (!hasSome(field, [ - ...props.field, + ...props.editable, ...props.validation, ...props.functions, ...props.handlers, diff --git a/tests/data/forms/nested/form.v.ts b/tests/data/forms/nested/form.v.ts index 8b1f74af..b411800e 100644 --- a/tests/data/forms/nested/form.v.ts +++ b/tests/data/forms/nested/form.v.ts @@ -11,6 +11,9 @@ const hooks = { onInit(form: FormInterface) { form.$('user.id').set('value', 'user-id'); form.$('user.name').set('value', 'user-init'); + form.$('user.name').set('disabled', true); + form.$('user.name').set('ref', "ref"); + }, onChange(form: FormInterface) { form.$('user.name').set('value', 'user-changed'); diff --git a/tests/nested.hooks.ts b/tests/nested.hooks.ts index 3b070ee2..15646966 100644 --- a/tests/nested.hooks.ts +++ b/tests/nested.hooks.ts @@ -29,6 +29,12 @@ describe('Check form onChange hook', () => { it('$V test.email value should be equal "test@email"', () => expect($.$V.$('test.email').value).to.be.equal('test@email')); + + it('$V user.name disabled should be true', () => + expect($.$V.$('user.name').disabled).to.be.true); + + it('$V user.name ref should be equal "ref"', () => + expect($.$V.$('user.name').ref).to.be.equal("ref")); }); describe('Check form onChange hook after reset', () => {