【发布时间】:2021-09-20 12:58:36
【问题描述】:
我有两个带有一个提交按钮的表单。这里我的问题是,我对两种表单都进行了验证。但我希望这些验证单独工作,就像当我提交 clusterForm 时,它应该验证并且应该发生后调用。但直到我填写其他表格才发生。这是我的 ts 代码。
sendclusteridApi() {
this.submitted = true;
if (this.clusterForm.invalid) {
return;
} else if (this.productFG.invalid) {
return;
}
const request = this.createRequest();
this.projectclosterservice.postStoryStatus(request).subscribe(
(res: any) => {
this.filtering = res["1tool-gitlab-pipeline"].data.filtering;
this.clusterForm.reset();
this.formData.reset();
},
(error) => {}
);
}
Html:clusterform
<div *ngIf="submitted && fclusterForm.clusternames.errors" class="error-feedback error">
<p *ngIf="fclusterForm.clusternames.errors?.required" class="text-danger ">
Please select Cluster
</p>
</div>
productFG 表单:及其控件
<div *ngIf="submitted && isTouchedAndRequired(i, key)" class="error-feedback error">
<p class="text-danger">{{key | titlecase}} is required.</p>
</div>
<div class="d-flex justify-content-end">
<button (click)="sendclusteridApi()" class="btn btn-primary px-3 py-2">Save</button>
</div>
【问题讨论】:
-
productFG提交时要调用哪个方法
-
两种表单的调用后方法相同,但是当我提交集群表单时,它要求我填写我不想填写的 productfg 表单。
标签: angular validation