Skip to content

Commit

Permalink
feat(form): add chang events in tag and checkbox, close #426
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed May 11, 2018
1 parent d313911 commit ed91cee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/form/src/widgets/checkbox/checkbox.widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SFSchemaEnum } from '../../schema';
<label nz-checkbox
[nzDisabled]="disabled"
[ngModel]="value"
(ngModelChange)="setValue($event)">
(ngModelChange)="_setValue($event)">
<span [innerHTML]="schema.title"></span>
<span class="optional">
{{ ui.optional }}
Expand Down Expand Up @@ -95,10 +95,18 @@ export class CheckboxWidget extends ControlWidget {
);
}

_setValue(value: any) {
this.setValue(value);
this.detectChanges();
this.notifyChange(value);
}

notifySet() {
const checkList = this.data.filter(w => w.checked);
this.updateAllChecked().setValue(
this.data.filter(w => w.checked).map(item => item.value),
checkList.map(item => item.value),
);
this.notifyChange(checkList);
}

groupInGridChange(values: any[]) {
Expand Down Expand Up @@ -127,4 +135,8 @@ export class CheckboxWidget extends ControlWidget {
this.detectChanges();
return this;
}

private notifyChange(res: boolean | SFSchemaEnum[]) {
if (this.ui.change) this.ui.change(res);
}
}
1 change: 1 addition & 0 deletions packages/form/src/widgets/checkbox/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ size | 大小,等同 `nzSize` | `string` | -
styleType | radio的样式 | `default, button` | `default`
checkAll | 是否需要全选 | `boolean` | -
checkAllText | 全选按钮文本 | `string` | `全选`
change | 值变更事件,参数:单个多选框为 `boolean`,否则为 `SFSchemaEnum[]` | `(res: boolean | SFSchemaEnum[]) => void` | -
3 changes: 3 additions & 0 deletions packages/form/src/widgets/tag/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ enum | 数据源 | `SFSchemaEnumType[]` | -
参数 | 说明 | 类型 | 默认值
----|------|-----|------
asyncData | 异步数据源 | `() => Observable<SFSchemaEnumType[]>` | -
afterClose | 关闭动画完成后的回调 | `() => void` | -
onClose | 关闭时的回调,在 `nzMode="closable"` 时可用 | `(e:MouseEvent) => void` | -
checkedChange | 设置标签的选中状态的回调 | `(status: boolean) => void` | -
11 changes: 11 additions & 0 deletions packages/form/src/widgets/tag/tag.widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { getData } from '../../utils';
*ngFor="let i of data"
nzMode="checkable"
[nzChecked]="i.checked"
(nzAfterClose)="_afterClose()"
(nzOnClose)="_close($event)"
(nzCheckedChange)="onChange(i)">
{{i.label}}
</nz-tag>
Expand All @@ -35,6 +37,15 @@ export class TagWidget extends ControlWidget {
onChange(item: SFSchemaEnum) {
item.checked = !item.checked;
this.updateValue();
if (this.ui.checkedChange) this.ui.checkedChange(item.checked);
}

_afterClose() {
if (this.ui.afterClose) this.ui.afterClose();
}

_close(e: any) {
if (this.ui.onClose) this.ui.onClose(e);
}

private updateValue() {
Expand Down

0 comments on commit ed91cee

Please sign in to comment.