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.

statusChanges is not fired upon dynamic validation added with NG_VALIDATOR

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/forms

Is this a regression?

Probably not

Description

You can create directives that provide NG_VALIDATOR token so additional validation can be applied. Simple case, I have a checkbox that hides a particular field. If the field is enabled, I want it to be required. I can do this with built-in required directive. When I toggle my field, form becomes invalid because it is empty and required. However statusChanges stream does not fire to let me know that form became INVALID

πŸ”¬ Minimal Reproduction

https://stackblitz.com/edit/angular-ng-validator-bug

🌍 Your Environment

Angular Version:

10.0.1

Anything else relevant? Watch out for ExpressionChanged error, form does actually become invalid the moment directive with NG_VALIDATOR is instantiated but the binding does not update. That’s how I actually got to use statusChanges stream and noticed it’s not firing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
waterpleacommented, Aug 12, 2020

Got it, thanks for the quick reply. In case it’s helpful, here’s the actual case where I ran into this: https://stackblitz.com/edit/angular-declarative-dynamic-validation?file=src%2Fapp%2Fvalidator%2Fvalidator.directive.ts&s=09

I was investigating declarative approaches to dynamic validation, as opposed to imperative setValidators calls. Since it’s dynamic I had to call validation manually anyway, so it’s not blocking, but still rather strange behaviour.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 13, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular form.statusChanges not working with dynamic form + ...
It looks like it is done by design. It is not firing the status change because it is invalid on initialization (or on...
Read more >
StatusChanges in Angular Forms - TekTutorialsHub
The StatusChanges event is fired whenever the angular calculates the validity status of the FormControl, FormGroup or FormArray. It is anΒ ...
Read more >
Angular Form Validation on Blur and Submit - Fiyaz Hasan
In Angular 5 , two new form validation techniques are introduced. ... Control (s) change on a submit event fired on the native...
Read more >
How to do Conditional Validation on valueChanges method in ...
In this blog post, we will learn to use Angular Reactive Forms value change detection and enable conditional validation on basis of that....
Read more >
Dynamic Validation in Angular Reactive Forms | Angular Tutorial
Angular Tutorial:#angular #angulartutorial #nitishkaushikGitHub Repo:Β ...
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