Object

Create an object widget, valid only for schema.type="object".

Examples

Basic Usage

Simplest of usage.

expand codeexpand code
import { Component } from '@angular/core';
import { SFSchema } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'form-object-simple',
  template: `<sf [schema]="schema" (formSubmit)="submit($event)"></sf>`,
})
export class FormObjectSimpleComponent {
  schema: SFSchema = {
    properties: {
      name: { type: 'string' },
      age: { type: 'number' },
    },
    required: ['name', 'age'],
    ui: {
      // 指定 `label` 和 `control` 在一行中各占栅格数
      spanLabel: 4,
      spanControl: 5,
    },
  };

  constructor(private msg: NzMessageService) {}

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

A basic card containing a title, content and an extra corner content.

expand codeexpand code
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { SFObjectWidgetSchema, SFSchema } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'form-object-card',
  template: `
    <sf *ngIf="schema" [schema]="schema" (formSubmit)="submit($event)"></sf>
    <ng-template #extra>
      <a (click)="msg.success('Success')">More</a>
    </ng-template>
  `,
})
export class FormObjectCardComponent implements OnInit {
  @ViewChild('extra', { static: true }) private extra!: TemplateRef<void>;
  schema?: SFSchema;

  constructor(public msg: NzMessageService) {}

  ngOnInit(): void {
    this.schema = {
      properties: {
        name: { type: 'string' },
        age: { type: 'number' },
        address1: {
          title: '地址1',
          type: 'object',
          properties: {
            country: { type: 'string' },
            city: { type: 'string' },
            zone: { type: 'string' },
          },
          ui: {
            type: 'card',
            cardExtra: this.extra,
          } as SFObjectWidgetSchema,
        },
        address2: {
          title: '地址2',
          type: 'object',
          properties: {
            country: { type: 'string' },
            city: { type: 'string' },
            zone: { type: 'string' },
          },
          ui: {
            type: 'card',
            showExpand: false,
          } as SFObjectWidgetSchema,
        },
      },
      required: ['name', 'age'],
      ui: {
        spanLabelFixed: 150,
        grid: { span: 12, gutter: 16 },
      } as SFObjectWidgetSchema,
    };
  }

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

API

schema

PropertyDescriptionTypeDefault
[properties]Defining the properties of an object schema{ [key: string]: SFSchema }-
[required]The data object to be valid should contain all properties with names equal to the elements in the keyword valuestring[]-
[maxProperties]The data object to be valid should have not more (less) properties than the keyword valuenumber-
[minProperties]The data object to be valid should have not more (less) properties than the keyword valuenumber-

ui

PropertyDescriptionTypeDefault
[showExpand]Whether to show the card body, click to hide the content, only type ==='card'booleantrue
[expand]Expanded state, only type ==='card'booleantrue
[showTitle]Whether to display the titlebooleanfalse
[type]Render type of objectcard, defaultdefault
[cardSize]The same as nzSizesmall, defaultsmall
[cardBodyStyle]The same as nzBodyStyle{ [key: string]: string }-
[cardBorderless]The same as nzBorderlessbooleanfalse
[cardExtra]The same as nzExtrastring, TemplateRef<void>-
[cardActions]The same as nzActionsArray<TemplateRef>-