【发布时间】:2018-01-18 14:23:01
【问题描述】:
在 Ionic 3 / Angular 5 应用程序中,我有一个由 3 个字段组成的表单:
- 名字(输入文本)
- 生日(日期时间选择器)
- 头像(单选按钮)
如果表单无效,提交按钮将被禁用:
[disabled]="!addChildForm.valid"
在初始化时,我会检查用户是在创建一个新的孩子还是在编辑一个。我编辑,我以编程方式填充字段。 这工作正常,但提交按钮无效。虽然出生日期已经很好地填充了,但我必须单击它来打开(和关闭)选择器以启用提交按钮。
我的代码:
createForm(child?: Child): void {
this.addChildForm = this.formBuilder.group({
firstnameInput: ['', Validators.required],
birthdateInput: ['', Validators.required],
avatarInput: ['', Validators.required]
});
// If we are editing a child, populate the form
if (child) {
this.addChildForm.setValue({
firstnameInput: child.firstname,
birthdateInput: moment(child.birthdate).format(),
avatarInput: child.avatar
});
}
}
知道如何在填充表单后强制表单进行检查以启用提交按钮吗?
【问题讨论】:
标签: angular ionic-framework angular-reactive-forms angular-forms