Skip to content

Commit

Permalink
fix: ref computed, allow set ref
Browse files Browse the repository at this point in the history
ref computed, allow set ref
  • Loading branch information
foxhound87 committed Mar 30, 2023
1 parent 870399e commit 7f20503
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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()`
Expand Down
2 changes: 1 addition & 1 deletion src/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
11 changes: 6 additions & 5 deletions src/props.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -31,6 +31,7 @@ export const props: PropsGroupsInterface = {
FieldPropsEnum.deleted,
FieldPropsEnum.disabled,
FieldPropsEnum.autoFocus,
FieldPropsEnum.ref,
],
handlers: [
FieldPropsEnum.onChange,
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const hasProps = ($type: any, $data: any) => {
break;
case "field":
$props = [
...props.field,
...props.editable,
...props.validation,
...props.functions,
...props.handlers,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions tests/data/forms/nested/form.v.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 6 additions & 0 deletions tests/nested.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 7f20503

Please sign in to comment.