我有兩個帶有一個提交按鈕的表單。我的問題是,我為兩個表單都設定了驗證,但我希望這些驗證是單獨作業的,比如當我提交clusterForm時,它應該被驗證,并且應該發生post call,但它在我填寫另一個表單時才發生。下面是我的ts代碼。
sendclusteridApi(/span>) {
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-ipeline"].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">
請選擇集群
</p>
</div>/span>
productFG form: and its controls
<div *ngIf="submitted &。 & isTouchedAndRequired(i, key)" class="error-feedback error">
<p class="text-danger">{{key | titlecase}}是必填的。 </p>
</div>/span>
<div class="d-flex justify-content-end"/span>>
< button (click)="sendclusteridApi()" class="btn btn-primary px-3 py-2" > 保存</按鈕>
</div>/span>
uj5u.com熱心網友回復:
試試下面的代碼
如果(this.clusterForm.invalid || (this.checkedIDs.length!=0&& this.productFG.invalid)){
this.errorMsg="請填寫所有表格條目。";
return false;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/328675.html
標籤:
下一篇:如果HTTP協議沒有EOF字符,為什么HttpURLConnection的readlinewhile回圈沒有阻塞?
