Skip to content

Commit

Permalink
fix(form:widget:array): fix error remove notify (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Feb 1, 2024
1 parent 6920137 commit 4957399
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/form/src/model/array.property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ArrayProperty extends PropertyGroup {
// TODO: 受限于 sf 的设计思路,对于移除数组项需要重新对每个子项进行校验,防止错误被父级合并后引起始终是错误的现象
if (property instanceof ObjectProperty) {
property.forEachChild(p => {
p.updateValueAndValidity();
p.updateValueAndValidity({ emitValueEvent: false });
});
}
});
Expand Down
13 changes: 10 additions & 3 deletions packages/form/src/widgets/array/array.widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
}

0 comments on commit 4957399

Please sign in to comment.