Easier Cross-field-validation for mat-form-field/mat-error combinations
- 主要言語
- TypeScript
- スター
- 25k
- フォーク
- 6.8k
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 91
説明
#### Feature Description
In reactive forms, cross-field validation requires the validation logic to be placed with the parent form instead of the individual control.
The existing feature works fine, however, changing the relevant `mat-form-field`(s) into an error-state to enable showing underlying `mat-error`(s) has to be done by calling the relevant `FormControl`'s `setErrors()` function.
However, with a directive, we need only to perform validation on the parent form and return `ValidationErrors`. The child controls can themselves detect whether they should go into error-state or not, and the developer need not worry further about it.
First, we run a normal validator function on the form that does nothing but return `ValidationErrors`. Then, we pass the key(s) of the error(s) for which we want cross-validation, to the custom directive.
Please note how the `mat-error`'s `*ngIf` depends upon the error-set of the `FormControl`, just like in normal validation, although it would still work if it depended on the error set of the parent `FormGroup` (which is what we do currently).
```
Range Start
Value must be less than End
```
#### Use Case
Developer convenience and ease of use. Brings more consistency between normal validation and cross-validation. Allows child controls to 'inherit' some user-specified errors of the parent on `valueChanges`.
#### StackBlitz
https://stackblitz.com/edit/angular-cross-validation-directive
コントリビューションガイド
調査の方向性
リンク先の StackBlitz の例から始めて、リアクティブな親フォーム、子 FormControls、mat-form-field、mat-error が現在どのように連携しているかを確認します。ディレクティブが選択された親フォームのエラーキーを受け取り、それらを該当する子コントロールで利用できるようにし、手動で setErrors() を呼び出さなくても mat-error が子コントロールのエラー状態を使用できるようになれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- angular, typescript
- 領域
- frontend
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100