我使用的是angular 6中的handsontable。
我尝试了添加自定义验证的代码,这在我的angular 6组件的官方文档中显示,但它不起作用。
我搜索了几个站点,但没有找到任何示例来说明如何在handsOntable的angular 2+版本中添加自定义验证
有人能告诉我如何在angular 2+版本中注册自定义验证吗?
提前感谢:)
发布于 2019-02-18 18:49:27
创建了一个用于电子邮件的示例自定义验证器,并能够设置为列
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
https://stackoverflow.com/questions/54742219
复制相似问题