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.

requiredTrue doesn't set a control to be `INVALID` when its value is not `true`

See original GitHub issue

See comment thread

🐞 bug report

Affected Package

The issue is caused by package @angular/....

β€œ@angular/forms”: β€œ^8.0.2”

Is this a regression?

Not sure

Description

I change validation rules on fly by setting Validators.requriedTrue however the control which has whatever value but true is still valid and my form is ready to submit (meanwhile it shouldn’t).

I use this.formGroup.get(...).setValidators(Validators.requiredTrue). The validator is set, but form is still valid although the value of the control is null or false

A clear and concise description of the problem...

πŸ”¬ Minimal Reproduction

https://stackblitz.com/edit/angular-wrokpb

Click the button to toggle the requiredTrue and see in console logged FormGroup object.

πŸ”₯ Exception or Error





🌍 Your Environment

Angular Version:




Angular CLI: 8.0.4
Node: 12.5.0
OS: linux x64
Angular: 8.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.800.4
@angular-devkit/build-angular      0.800.4
@angular-devkit/build-ng-packagr   0.800.4
@angular-devkit/build-optimizer    0.800.4
@angular-devkit/build-webpack      0.800.4
@angular-devkit/core               8.0.4
@angular-devkit/schematics         8.0.4
@angular/cdk                       8.0.1
@angular/cli                       8.0.4
@angular/material                  8.0.1
@angular/material-moment-adapter   8.0.1
@ngtools/json-schema               1.1.0
@ngtools/webpack                   8.0.4
@schematics/angular                8.0.4
@schematics/update                 0.800.4
ng-packagr                         5.3.0
rxjs                               6.5.2
typescript                         3.4.5
webpack                            4.30.0

Anything else relevant?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonadencommented, Jul 11, 2019

You’re correct, this should be noted in the docs for setValidators. I’m moving this to a docs issue.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 15, 2019

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

How can I manually set an Angular form field as invalid?
To set validation error in component: formData.form.controls['email'].setErrors({'incorrect': true});. To unset validation error in ...
Read more >
Chapter 11. Validating forms - Angular Development with ...
In this chapter, we'll show you how to validate forms in Angular using built-in validators and ... requiredTrue, The form control must have...
Read more >
aria-invalid - Accessibility - MDN Web Docs
If a value is determined to be invalid or out-of-range, set aria-invalid="true" and tell the user there is an error. For better user...
Read more >
Form fields - Django documentation
Normalizes to: A Python True or False value. Validates that the value is True (e.g. the check box is checked) if the field...
Read more >
The best way to implement custom validators - Angular inDepth
wrongColor}} is wrong </div>. To make our custom validator accessible for template-driven forms, we need to implement our validator as a directive andΒ ......
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