How to have validatorFN for FormControl inside getFormControls() ?
See original GitHub issueI know there is getFormGroupControlOptions
but this is validation for the entire formGroup right? (as indicated by (formGroup) => {}
) - FormGroup - level.
How can I use validation on a FormControl level?
Here in my stackblitz im using the same validatorFN validatorWithDeps
in a normal angular way and inside getFormControls() the ngx-sub-form way. How can I yield the same results? For ngx-sub-form its undefined. (because of scoping …)
Steps to reproduce:
- open browser-console
- type stuff into top field (“Enter you email”)
- type stuff into field with “12345” in it.
- For top field the validator can resolve the values. For ngx-sub-form it cant.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
Building Custom Validators in Angular
In this function, we will get complete form control using AbstractControl , which is the base class for FormControl , FormGroup , and...
Read more >In Angular, how to add Validator to FormControl after ...
A simple solution would be to first get all the validators in the form control and assign a new validatorFn to it when...
Read more >The best way to implement custom validators - Angular ...
First, we will have a look at some built-in operators and then learn how to implement a custom validator on our own (this...
Read more >Angular Custom Form Validators: Complete Guide
All about custom form validators, including synchronous and asynchronous, field-level, form-level, for both template-driven and reactive ...
Read more >formcontrolname must be used with a parent formgroup ...
Example: <div [formGroup]="myGroup"> <input formControlName="firstName"> </div> In your class: this.myGroup = new FormGroup({ firstName: new FormControl() }); ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @andreElrico,
I took some time this evening to investigate. Thanks for the stackblitz repro it helped a lot.
If you look into this comment: https://github.com/microsoft/TypeScript/issues/1617#issuecomment-69215655
You’ll notice that:
As of today, the creation of the
formGroup
is happening in the constructor and therefore, thegetFormControls
method from the sub class is called when the properties of the sub class are not initialized yet.https://github.com/cloudnc/ngx-sub-form/blob/1956d258b705bd4e489d0f3a46419c1bc135d8d3/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts#L72-L75
I’m working on a fix but I suspect it might be a (small) breaking change.
EDIT:
I’ve got the fix working just need to edit some tests
🎉 This issue has been resolved in version 5.2.0-feat-rewrite.1 🎉
The release is available on:
Your semantic-release bot 📦🚀