You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
formGroup disable()/enable() does not work right after init #22556
I you create a formGroup using formBuilder.group() and call formGroup.disable() or formGroup.enable() right after initialization then it doesn't work.
If you call it using button or setTimeout() then it works.
Expected behavior
Would be nice to be able to disable/enable form right after creation.
Minimal reproduction of the problem with instructions
Reacted by Guilherme Ventura, Tjaart van der Walt, Milena Dimovska, Jason Yeomans, G. Pires, John Youngers, Adrian Macuc, Angel Daniel Alonso Tovar, adamdport, Vlad Poluch and 55 more
I am as well: I have a class that extends FormGroup, where in the constructor it just calls super({...}) to populate the form, then calls disable().
If I dispatch a new instance of this object to the state, the form in the UI does not render as I'd expect (if the old form was enabled, the fields will still be enabled).
If I wrap the .disable() line in a setTimeout(), then it works as you'd expect.
Reacted by Aleksandar Milutinovic, tanzeelrana901223, POLAKv93, Ricardo Reais and Amir Hesari
The warehouse is the root for a whole structure, there might be something down the line that updates value/validity, but nothing, I repeat, nothing, touches the warehouse itself.
How is that even possible?
Why is "enabled/disabled" even related to status? (valid beats disabled, so my money is on a validator that "enables" its control and it propagates it up... because that was obviously my intention when I added some validator somewhere... to enable the whole form... ).
Activity
Toxicable commentedon Mar 3, 2018
Could you explain the steps to reproduce, I don't see anything wrong in your stack blitz
ctrl-brk commentedon Mar 3, 2018
Click on "Disable with init" button. It will not disable the form. Or click any other "Disable" and than "Enable with init".
danguilherme commentedon Jun 1, 2018
I am having the same issue, here is a summary of my setup:
component.ts
component.html
Changing
this.disabledGroup.disable()tosetTimeout(() => this.disabledGroup.disable());works as expected.ng version_ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/Angular CLI: 6.0.3
Node: 8.11.2
OS: darwin x64
Angular: 6.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.6.1
@angular-devkit/build-angular 0.6.1
@angular-devkit/build-ng-packagr 0.6.3
@angular-devkit/build-optimizer 0.6.1
@angular-devkit/core 0.6.1
@angular-devkit/schematics 0.6.3
@angular/cli 6.0.3
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.0.1
@schematics/angular 0.6.3
@schematics/update 0.6.3
ng-packagr 3.0.0-rc.5
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
tjaartvanderWalt commentedon Sep 7, 2018
I Have the same issue, you can find a minimal working example here
Environment
Angular version: 6.1.0
Dead96 commentedon Sep 11, 2018
This simple directive works for me:
Tested on Angular@6.0.5
UPDATE: Fix calling enable/disable loop
giovannipds commentedon Dec 18, 2018
I'm experiencing the same issue. Nothing new about it?
lppedd commentedon Jan 21, 2019
Same issue on the latest version.
Damn guys, I was literally going crazy to find what was happening
JohnYoungers commentedon Jan 28, 2019
I am as well: I have a class that extends
FormGroup, where in the constructor it just callssuper({...})to populate the form, then callsdisable().If I dispatch a new instance of this object to the state, the form in the UI does not render as I'd expect (if the old form was enabled, the fields will still be enabled).
If I wrap the
.disable()line in asetTimeout(), then it works as you'd expect.38 remaining items
GonziHere commentedon Apr 28, 2021
The warehouse is the root for a whole structure, there might be something down the line that updates value/validity, but nothing, I repeat, nothing, touches the warehouse itself.
How is that even possible?
Why is "enabled/disabled" even related to status? (valid beats disabled, so my money is on a validator that "enables" its control and it propagates it up... because that was obviously my intention when I added some validator somewhere... to enable the whole form... ).
PS: my issue wasn't solvable by timeouts.
fix(forms): not picking up disabled state if group is swapped out and…
fix(forms): not picking up disabled state if group is swapped out and…
angular-automatic-lock-bot commentedon Apr 28, 2022
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.