手动设置表单上的验证
我有以下问题:
我有一个具有多个字段的表格。我使用以下功能将更多表单字段添加到表单中。
它检查是否存在填充表单字段的最小数量并具有输入。如果是这种情况,请激活提交按钮。
但是,如果表格不有效,则禁用提交按钮。
我的问题是如何手动设置表格有效?
addFormFieldsWithInput(fields: string[]): void {
let controlArray=[];
const groupObj = {};
for (let i = 0; (i < fields.length); i++) {
controlArray.push((this.feedbackInviteForm.get(type) as FormArray).push(this.formBuilder.control(fields[i])));
this.formFieldsLength++;
groupObj = this.formBuilder.array(controlArray);
}
if(fields.length>=this.minFormFieldsLength){
this.form = this.formBuilder.group(groupObj)
}
}
通过此实现,该按钮将被禁用,并添加适量的表单字段,但没有输入,并且表单字段为空。
I have the following problem:
I have a form with several fields. I use the function below to add more form fields to the form.
It checks if the minimum number of filled form fields are present and have input. If this is the case, the submit button is activated.
However, the submit button is disabled if the form is not valid.
My question is how can I manually set the form to be valid?
addFormFieldsWithInput(fields: string[]): void {
let controlArray=[];
const groupObj = {};
for (let i = 0; (i < fields.length); i++) {
controlArray.push((this.feedbackInviteForm.get(type) as FormArray).push(this.formBuilder.control(fields[i])));
this.formFieldsLength++;
groupObj = this.formBuilder.array(controlArray);
}
if(fields.length>=this.minFormFieldsLength){
this.form = this.formBuilder.group(groupObj)
}
}
With this implementation the button will be disabled and it adds the right amount of form fields but there is no input and the form fields are empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将该逻辑放在组验证器中。
这是一个例子:
formGroup验证器
Put that logic in a group validator, then.
Here's an example:
FormGroup validator