diff --git a/package.json b/package.json index 6576e14..73b87e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "axp-ts", - "version": "1.9.8", + "version": "1.9.9", "description": "TypeScript helper library", "author": "AntoXa PRO ", "homepage": "https://antoxahub.ru/antoxa/axp-ts", diff --git a/src/forms/model.ts b/src/forms/model.ts index 11179a9..f22940e 100644 --- a/src/forms/model.ts +++ b/src/forms/model.ts @@ -3,7 +3,6 @@ import type { TNotificationItem } from '../notification' import { FormSchemaCtrl } from './ctrl' - /** * Интерфейс базовой формы для сущностей в БД. */ @@ -17,7 +16,7 @@ export interface IFormModel { obj: T ctrls: FormSchemaCtrl[] - _errors: {[PropKey in keyof T]?: string} + _errors: { [PropKey in keyof T]?: string } errors: TNotificationItem[] isValid(): boolean @@ -38,7 +37,7 @@ export class BaseFormModel implements IFormModel { schema: z.ZodObject ctrls: FormSchemaCtrl[] = [] - _errors: {[PropKey in keyof T]?: string} = {} + _errors: { [PropKey in keyof T]?: string } = {} constructor(obj: any = {}, schema: z.ZodObject) { this._id = obj._id || 'create' @@ -101,4 +100,9 @@ export class BaseFormModel implements IFormModel { mergeObj(obj: any) { this.obj = Object.assign(this.obj, obj) } + + updateCtrl(key: keyof T, ctrl: Partial) { + const fieldIndex = this.ctrls.findIndex(e => e.key === key) + this.ctrls[fieldIndex] = Object.assign(this.ctrls[fieldIndex], ctrl) + } }