Loading libs/forms/CHANGELOG +4 −0 Original line number Diff line number Diff line # Changelog ## [0.11.0] ### Added - support for set value initial ## [0.10.1] ### Added - support for array group Loading libs/forms/package.json +1 −1 Original line number Diff line number Diff line { "name": "@rxap/forms", "version": "0.10.1", "version": "0.11.0", "private": false, "author": "Merzough Münker", "homepage": "https://gitlab.com/rxap/packages", Loading libs/forms/src/lib/decorators/control-set-value.ts +10 −4 Original line number Diff line number Diff line import { setMetadataMapSet } from '@rxap/utilities'; import { MetadataKeys } from './metadata-keys'; export function ControlSetValue(...controlIds: string[]) { export interface ControlSetValueOptions { propertyKey: string; initial?: boolean; } export function ControlSetValue(controlId: string, options: Omit<ControlSetValueOptions, 'propertyKey'> = {}) { return function(target: any, propertyKey: string) { for (const controlId of controlIds) { setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_SET_VALUE, target); } setMetadataMapSet(controlId, { ...options, propertyKey }, MetadataKeys.CONTROL_SET_VALUE, target); }; Loading libs/forms/src/lib/form-builder.ts +19 −9 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import { RxapFormArray } from './form-array'; import { RxapFormGroup } from './form-group'; import { RxapFormControl } from './form-control'; import { GetDefinitionMetadata } from '@rxap/definition'; import { ControlSetValueOptions } from './decorators/control-set-value'; export class FormArrayControlManager<T extends FormDefinition> { Loading Loading @@ -69,7 +70,7 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { private readonly validators: Map<string, Set<string>>; private readonly asyncValidators: Map<string, Set<string>>; private readonly controlChanges: Map<string, Set<string>>; private readonly controlSetValue: Map<string, Set<string>>; private readonly controlSetValue: Map<string, Set<ControlSetValueOptions>>; private readonly providers: StaticProvider[]; Loading Loading @@ -147,6 +148,17 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { form.rxapOnInit(); } for (const control of Object.values(form.rxapFormGroup.controls)) { if (control.controlId) { const controlSetValueOnInit = Array.from(this.controlSetValue.get(control.controlId) ?? []) .filter(controlSetValueOptions => controlSetValueOptions.initial); for (const onSetValue of this.coerceToFnArray<SetValueFn>(form, controlSetValueOnInit)) { onSetValue(control.value); } } } return form; } Loading Loading @@ -352,19 +364,17 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { * @param methodKeys A set of propertyKeys that points to form * definition instance methods */ private coerceToFnArray<T extends Function>(form: Form & Record<string, Function>, methodKeys?: Set<string>): Array<T> { private coerceToFnArray<T extends Function>(form: Form & Record<string, Function>, methodKeys?: Iterable<string | { propertyKey: string }>): Array<T> { const changes: Array<T> = []; if (methodKeys) { methodKeys.forEach(propertyKey => { for (const propertyKeyOrOptions of methodKeys) { const propertyKey = typeof propertyKeyOrOptions === 'string' ? propertyKeyOrOptions : propertyKeyOrOptions.propertyKey; assertIsFunction(form[ propertyKey ]); changes.push((form[ propertyKey ] as T).bind(form)); }); } } Loading Loading @@ -441,8 +451,8 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { return getMetadata(MetadataKeys.CONTROL_CHANGES, this.definition.prototype) ?? new Map<string, Set<string>>(); } private extractControlSetValue(): Map<string, Set<string>> { return getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype) ?? new Map<string, Set<string>>(); private extractControlSetValue(): Map<string, Set<ControlSetValueOptions>> { return getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype) ?? new Map<string, Set<ControlSetValueOptions>>(); } private extractValidators(): Map<string, Set<string>> { Loading Loading
libs/forms/CHANGELOG +4 −0 Original line number Diff line number Diff line # Changelog ## [0.11.0] ### Added - support for set value initial ## [0.10.1] ### Added - support for array group Loading
libs/forms/package.json +1 −1 Original line number Diff line number Diff line { "name": "@rxap/forms", "version": "0.10.1", "version": "0.11.0", "private": false, "author": "Merzough Münker", "homepage": "https://gitlab.com/rxap/packages", Loading
libs/forms/src/lib/decorators/control-set-value.ts +10 −4 Original line number Diff line number Diff line import { setMetadataMapSet } from '@rxap/utilities'; import { MetadataKeys } from './metadata-keys'; export function ControlSetValue(...controlIds: string[]) { export interface ControlSetValueOptions { propertyKey: string; initial?: boolean; } export function ControlSetValue(controlId: string, options: Omit<ControlSetValueOptions, 'propertyKey'> = {}) { return function(target: any, propertyKey: string) { for (const controlId of controlIds) { setMetadataMapSet(controlId, propertyKey, MetadataKeys.CONTROL_SET_VALUE, target); } setMetadataMapSet(controlId, { ...options, propertyKey }, MetadataKeys.CONTROL_SET_VALUE, target); }; Loading
libs/forms/src/lib/form-builder.ts +19 −9 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import { RxapFormArray } from './form-array'; import { RxapFormGroup } from './form-group'; import { RxapFormControl } from './form-control'; import { GetDefinitionMetadata } from '@rxap/definition'; import { ControlSetValueOptions } from './decorators/control-set-value'; export class FormArrayControlManager<T extends FormDefinition> { Loading Loading @@ -69,7 +70,7 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { private readonly validators: Map<string, Set<string>>; private readonly asyncValidators: Map<string, Set<string>>; private readonly controlChanges: Map<string, Set<string>>; private readonly controlSetValue: Map<string, Set<string>>; private readonly controlSetValue: Map<string, Set<ControlSetValueOptions>>; private readonly providers: StaticProvider[]; Loading Loading @@ -147,6 +148,17 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { form.rxapOnInit(); } for (const control of Object.values(form.rxapFormGroup.controls)) { if (control.controlId) { const controlSetValueOnInit = Array.from(this.controlSetValue.get(control.controlId) ?? []) .filter(controlSetValueOptions => controlSetValueOptions.initial); for (const onSetValue of this.coerceToFnArray<SetValueFn>(form, controlSetValueOnInit)) { onSetValue(control.value); } } } return form; } Loading Loading @@ -352,19 +364,17 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { * @param methodKeys A set of propertyKeys that points to form * definition instance methods */ private coerceToFnArray<T extends Function>(form: Form & Record<string, Function>, methodKeys?: Set<string>): Array<T> { private coerceToFnArray<T extends Function>(form: Form & Record<string, Function>, methodKeys?: Iterable<string | { propertyKey: string }>): Array<T> { const changes: Array<T> = []; if (methodKeys) { methodKeys.forEach(propertyKey => { for (const propertyKeyOrOptions of methodKeys) { const propertyKey = typeof propertyKeyOrOptions === 'string' ? propertyKeyOrOptions : propertyKeyOrOptions.propertyKey; assertIsFunction(form[ propertyKey ]); changes.push((form[ propertyKey ] as T).bind(form)); }); } } Loading Loading @@ -441,8 +451,8 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> { return getMetadata(MetadataKeys.CONTROL_CHANGES, this.definition.prototype) ?? new Map<string, Set<string>>(); } private extractControlSetValue(): Map<string, Set<string>> { return getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype) ?? new Map<string, Set<string>>(); private extractControlSetValue(): Map<string, Set<ControlSetValueOptions>> { return getMetadata(MetadataKeys.CONTROL_SET_VALUE, this.definition.prototype) ?? new Map<string, Set<ControlSetValueOptions>>(); } private extractValidators(): Map<string, Set<string>> { Loading