如何在角度2+中添加自定义验证

问题描述 投票:0回答:1

我在角度6中使用了双手。

我尝试使用代码添加自定义验证,这些验证显示在我的angular 6组件的官方文档中,但它不起作用。

我搜索了几个网站,但没有找到任何一个示例,说明如何在角度2+版本中为handsOntable添加自定义验证

任何人都可以让我知道如何在角度2+版本中注册自定义验证

提前致谢 :)

javascript angular angular6 handsontable
1个回答
2
投票

为电子邮件创建了示例自定义验证程序,并且可以设置为列

emailValidator = (value, callback) => {
  console.log(value)
  setTimeout(function(){
    if (/.+@.+/.test(value)) {
      callback(true);
    }
    else {
      callback(false);
    }
  }, 1000);
};

private columns: any[] = [
{
  data: 'name'
},
{
  data: 'email',
  validator: this.emailValidator,
  // Uncomment below line accept invalid input and indicate
  // allowInvalid: true
}
];

@ViewChild(HotTableComponent) hotTableComponent;
// Call validator after initialization
afterInit() {  this.hotTableComponent.getHandsontableInstance().validateCells(function(valid){});

afterInit是一个事件发射器

<hot-table [data]="data"
       [colHeaders]="colHeaders"
       [columns]="columns"
       [options]="options"
       (hotInstanceCreated)="instanceCreated($event)"
       (afterInit)="afterInit(event$)"
       [colWidths]="colWidths">

https://stackblitz.com/edit/angular-kjmvq4?file=app%2Fapp.component.ts

© www.soinside.com 2019 - 2024. All rights reserved.