2
我需要幫助,我有一個很長的表單。當客戶點擊提交時,想要顯示未填寫的字段。如果我把一個錯誤的字段放到字段中(主播類型),我該怎麼辦?
模板:
<div class="container" [formGroup]="ClientForm">
<div class="form-group" [ngClass]="{'has-success':ClientForm.controls.input1.valid,'has-danger':!ClientForm.controls.input1.valid}">
<label>Input 1</label>
<input type="text" class="form-control" placeholder="Input 1" readonly formControlName="input1">
<small class="form-text text-muted" [hidden]="ClientForm.controls.input1.valid">This field is required!</small>
</div>
<hr>
<button type="submit" (click)="onSubmit(ClientForm)" class="btn btn-primary">Submit</button> Status: {{ClientForm.status}}
</div>
組件:
constructor(public fb: FormBuilder){}
ngOnInit() {
this.bluidForm();
}
bluidForm(): void {
this.ClientForm = this.fb.group({
input1 : new FormControl(null,Validators.required),
input2 : new FormControl(null,Validators.required),
input3 : new FormControl(null,Validators.required),
input4 : new FormControl(null,Validators.required),
input5 : new FormControl(null,Validators.required),
input6 : new FormControl(null,Validators.required),
input7 : new FormControl(null,Validators.required),
input8 : new FormControl(null,Validators.required),
input9 : new FormControl(null,Validators.required)
})
}
onSubmit(dataRecibe){
console.log(dataRecibe)
}
https://plnkr.co/edit/x5q7sVucARspL8bIITdQ?p=preview
你能幫助我嗎?
Ty的幫助。 –