Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form:widget:array): fix error remove notify #1758

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading