2017-01-12 5 views
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

あなたは私を助けることができますか?

答えて

0

シンプルで高速なソリューション、ちょうどそうのようなあなたのフィールドにrequiredを追加します。

<input type="text" class="form-control" placeholder="Input 2" formControlName="input2" required> 

メッセージが最初に空のフィールドから始めて、ブラウザに表示されます。

これはあなたが探していた解決策の種類でしたか?

お客様のPlunker

+0

タイです。 –

関連する問題