From 2fa5db2e0479087dd65dcba3796c3d1fa85b2e5b Mon Sep 17 00:00:00 2001 From: cipchk Date: Tue, 23 Jan 2024 14:41:34 +0800 Subject: [PATCH] fix(form:widget:array): fix error remove notify - close https://github.com/ng-alain/ng-alain/issues/2470 --- packages/form/src/model/array.property.ts | 2 +- packages/form/src/widgets/array/array.widget.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/form/src/model/array.property.ts b/packages/form/src/model/array.property.ts index 3b5bd5821..3a2158059 100644 --- a/packages/form/src/model/array.property.ts +++ b/packages/form/src/model/array.property.ts @@ -107,7 +107,7 @@ export class ArrayProperty extends PropertyGroup { // TODO: 受限于 sf 的设计思路,对于移除数组项需要重新对每个子项进行校验,防止错误被父级合并后引起始终是错误的现象 if (property instanceof ObjectProperty) { property.forEachChild(p => { - p.updateValueAndValidity(); + p.updateValueAndValidity({ emitValueEvent: false }); }); } }); diff --git a/packages/form/src/widgets/array/array.widget.ts b/packages/form/src/widgets/array/array.widget.ts index fdc5860d0..63217be8f 100644 --- a/packages/form/src/widgets/array/array.widget.ts +++ b/packages/form/src/widgets/array/array.widget.ts @@ -3,6 +3,7 @@ import { SafeHtml } from '@angular/platform-browser'; import { NzButtonType } from 'ng-zorro-antd/button'; +import { SFUpdateValueAndValidity } from '../../interface'; import type { FormProperty } from '../../model/form.property'; import { ArrayLayoutWidget } from '../../widget'; @@ -108,8 +109,13 @@ export class ArrayWidget extends ArrayLayoutWidget implements OnInit { this.removeTitle = removable === false ? null : removeTitle || this.l.removeText; } - private reValid(): void { - this.formProperty.updateValueAndValidity({ onlySelf: false, emitValueEvent: false, emitValidator: true }); + private reValid(options?: SFUpdateValueAndValidity): void { + this.formProperty.updateValueAndValidity({ + onlySelf: false, + emitValueEvent: false, + emitValidator: true, + ...options + }); } addItem(): void { @@ -119,8 +125,9 @@ export class ArrayWidget extends ArrayLayoutWidget implements OnInit { } removeItem(index: number): void { + const updatePath = (this.formProperty.properties as FormProperty[])[index].path; this.formProperty.remove(index); - this.reValid(); + this.reValid({ updatePath, emitValueEvent: true }); this.ui.remove?.(index); } }