ngx-formly:如何为自定义控件(如 dateTimePicker)以形式触发模糊事件?
ngx-formly: How to trigger blur event in formly for a custom control like dateTimePicker?
angular 中的自定义控件未正式触发模糊事件。如何为自定义组件绑定模糊事件?我已经为 dateTimePicker 创建了自定义控件,并使用 Material UI 和 angular 版本 9,正式版本 5.5
export class AppComponent {
form = new FormGroup({});
model: any = {};
options: FormlyFormOptions = {};
fields: FormlyFieldConfig[] = [
{
key: "DateTimePicker",
type: "dateTime",
templateOptions: {
label: "Accept terms",
description: "In order to proceed, please accept terms",
pattern: "true",
required: true,
blur: () => {
console.log("blur called");
}
},
validation: {
messages: {
pattern: "Please accept the terms"
}
}
}
];
}
formlyAttributes
指令处理模糊事件,因此请确保它在我们的文档 https://formly.dev/guide/custom-formly-field
中提到的自定义类型中定义
<input type="input"
[formControl]="formControl"
[formlyAttributes]="field"
/>
如果它不起作用或您的组件对模糊事件使用不同的输出名称,您必须声明它:
<input type="input"
(blur)="to.blur ? this.to.blur(this.field, $event): ''"
/>
angular 中的自定义控件未正式触发模糊事件。如何为自定义组件绑定模糊事件?我已经为 dateTimePicker 创建了自定义控件,并使用 Material UI 和 angular 版本 9,正式版本 5.5
export class AppComponent {
form = new FormGroup({});
model: any = {};
options: FormlyFormOptions = {};
fields: FormlyFieldConfig[] = [
{
key: "DateTimePicker",
type: "dateTime",
templateOptions: {
label: "Accept terms",
description: "In order to proceed, please accept terms",
pattern: "true",
required: true,
blur: () => {
console.log("blur called");
}
},
validation: {
messages: {
pattern: "Please accept the terms"
}
}
}
];
}
formlyAttributes
指令处理模糊事件,因此请确保它在我们的文档 https://formly.dev/guide/custom-formly-field
<input type="input"
[formControl]="formControl"
[formlyAttributes]="field"
/>
如果它不起作用或您的组件对模糊事件使用不同的输出名称,您必须声明它:
<input type="input"
(blur)="to.blur ? this.to.blur(this.field, $event): ''"
/>