0
私は、角度4のフォームとフォームグループコンポーネントを使用してデータの追加/編集フォームを作成しています。私は、新しいデータを追加する際に適切な検証をすることができますが、既に入力された入力フィールドで同じフォームを編集する際に問題があります。コードの下フォームビルダが値をあらかじめ入力しているときにフォームビルダを編集中に検証する方法はありますか?
は、コンポーネントの一部は次のとおりです。コードの下
this.saveNotification = this.formBuilder.group({
id: '',
name: ['', Validators.required],
question: ['', Validators.required],
repeatTypesControl: ['', Validators.required],
remindAt: '',
});
if(this.isUpdateCheck){///pre-filled form on Edit
this.saveNotification.patchValue({
id: 4,
name: "Deck",
question: "Who's Deck is this?",
remindAt: "08:30pm",
});
this.saveNotification.updateValueAndValidity();
for (var i in this.saveNotification.controls) {
this.saveNotification.controls[i].markAsTouched();
}
テンプレート部分である:
<button ion-button color="secondary" type="submit" [disabled]="(!saveNotification.valid)" color="dark">SAVE</button>
値を編集するにあたりを得ているので、私は常にfalseとしてsaveNotification.valid値を取得していますコンポーネントから埋められます。私はthis.saveNotification.controls [i] .markAsTouched()を試しましたが、これはうまくいきません。
のInsedは感謝が、コードの上に自分のコードが何を同じやる、それはフォームが有効なコントロールがありません。 'this.saveNotification.valid'がtrueになるようにフォームコントロールに値を設定した後、私は何をしたいですか? – Abu