Skip to content

Commit

Permalink
feat(form:select,cascader,tree-select): default value when cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Oct 18, 2024
1 parent 70e40b8 commit d64ae08
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/form/src/widgets/select/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ export interface SFSelectWidgetSchema extends SFUISchemaItem {
*/
clearIcon?: TemplateRef<NzSafeAny>;

/**
* 清空时默认值,默认:`undefined`
*/
clearValue?: NzSafeAny;

/**
* 自定义当前选中的条目图标
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/widgets/select/select.widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class SelectWidget extends ControlUIWidget<SFSelectWidgetSchema> implemen
if (this.ui.change) {
this.ui.change(values, this.getOrgData(values));
}
this.setValue(values == null ? undefined : values);
this.setValue(values == null ? this.ui.clearValue : values);
}

private getOrgData(values: SFValue): SFSchemaEnum | SFSchemaEnum[] {
Expand Down
5 changes: 5 additions & 0 deletions packages/form/widgets/cascader/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface SFCascaderWidgetSchema extends SFUISchemaItem {
*/
allowClear?: boolean;

/**
* 清空时默认值,默认:`undefined`
*/
clearValue?: NzSafeAny;

/**
* 清除按钮的标题,默认:`清除`
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/form/widgets/cascader/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class CascaderWidget extends ControlUIWidget<SFCascaderWidgetSchema> impl
}

_change(value: NzSafeAny[] | null): void {
this.setValue(value);
this.setValue(value == null ? this.ui.clearValue : value);
if (this.ui.change) {
this.ui.change(value);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/form/widgets/tree-select/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface SFTreeSelectWidgetSchema extends SFUISchemaItem {
*/
allowClear?: boolean;

/**
* 清空时默认值,默认:`undefined`
*/
clearValue?: NzSafeAny;

/**
* 下拉菜单和选择器同宽,默认:`true`
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/form/widgets/tree-select/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ export class TreeSelectWidget extends ControlUIWidget<SFTreeSelectWidgetSchema>
}

change(value: NzSafeAny[] | NzSafeAny): void {
console.log(value);
if (this.ui.change) this.ui.change(value);
this.setValue(value);
this.setValue(value == null ? this.ui.clearValue : value);
}

expandChange(e: NzFormatEmitEvent): void {
Expand Down

0 comments on commit d64ae08

Please sign in to comment.