ng-alain動態表單SF表單項設置必填和正則校驗

在使用動態表單時對錶單項進行非空校驗及正則校驗。
使用手機號進行校驗,示例以下:

動態表單的基本使用:https://ng-alain.com/form/get...javascript

基於基本示例,增長手機號必填與正則校驗的例子:java

@Component({
  selector: 'app-home',
  template: `
  <sf [schema]="schema" [ui]="ui" (formSubmit)="submit($event)"></sf>
  `
})
export class HomeComponent {
  schema: SFSchema = {
    properties: {
      email: {
        type: 'string',
        title: '郵箱',
        format: 'email',
        maxLength: 20
      },
      name: {
        type: 'string',
        title: '姓名',
        minLength: 3
      },
      mobileNumber: { type: 'string', title: '手機號', pattern: '^1[0-9]{10}$' },
    },
    
  };

  ui: SFUISchema = {
    '*': {
      spanLabelFixed: 100,
      grid: { span: 24 },
    },
    $mobileNumber: {
      widget: 'string',
      errors: { 'pattern': '請輸入11位手機號碼' }
    }
  };

  submit(value: any) {

  }
}
相關文章
相關標籤/搜索