question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to have validatorFN for FormControl inside getFormControls() ?

See original GitHub issue

I 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 …)

STACKBLITZ

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:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
maxime1992commented, Nov 11, 2019

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:

The order of initialization is:

The base class initialized properties are initialized
The base class constructor runs
The derived class initialized properties are initialized
The derived class constructor runs

As of today, the creation of the formGroup is happening in the constructor and therefore, the getFormControls 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

1reaction
maxime1992commented, Sep 13, 2020

🎉 This issue has been resolved in version 5.2.0-feat-rewrite.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found