Checkbox

Checkbox.

Examples

Basic Usage

Simplest of usage.

expand codeexpand code
import { Component } from '@angular/core';
import { SFCascaderWidgetSchema, SFCheckboxWidgetSchema, SFSchema } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd/message';
import { of, delay } from 'rxjs';

@Component({
  selector: 'form-checkbox-simple',
  template: ` <sf [schema]="schema" (formSubmit)="submit($event)"></sf> `,
})
export class FormCheckboxSimpleComponent {
  schema: SFSchema = {
    properties: {
      // 单个多选框
      single: {
        type: 'boolean',
        title: '同意本协议',
        description: '《用户协议》',
        ui: {
          widget: 'checkbox',
        } as SFCascaderWidgetSchema,
        default: true,
      },
      // 多选框组
      mulit: {
        type: 'string',
        title: 'Mulit',
        enum: ['Apple', 'Pear', 'Orange'],
        ui: {
          widget: 'checkbox',
          span: 8, // 指定每一项 8 个单元的布局
          checkAll: true,
        } as SFCheckboxWidgetSchema,
        default: ['Apple'],
      },
      // 异步数据
      async: {
        type: 'string',
        title: 'Async',
        ui: {
          widget: 'checkbox',
          asyncData: () =>
            of([
              { label: 'Apple', value: 'Apple' },
              { label: 'Pear', value: 'Pear' },
              { label: 'Orange', value: 'Orange' },
            ]).pipe(delay(200)),
        } as SFCheckboxWidgetSchema,
        default: ['Apple'],
      },
    },
  };

  constructor(private msg: NzMessageService) {}

  submit(value: {}): void {
    this.msg.success(JSON.stringify(value));
  }
}

API

schema

PropertyDescriptionTypeDefault
[readOnly]Whether to disable the stateboolean-
[enum]Render checkbox group when the value existsSFSchemaEnumType[]-
[title]Text of the single checkboxstring-
[description]Help text of the single checkboxstring-

ui

PropertyDescriptionTypeDefault
[asyncData]Async data source, render checkbox group when the value exists() => Observable<SFSchemaEnumType[]>-
[span]Raster number of cells to occupy, refer to layoutnumber-
[styleType]Style of the nz-checkboxdefault, buttondefault
[checkAll]Whether to select allboolean-
[checkAllText]Select all button textstring全选
[change]Changed event, Parameter: single checkbox is boolean, otherwise SFSchemaEnum[](res: boolean | SFSchemaEnum[]) => void-