Skip to content

Updating disabled state after replacing FormGroup. #18381

Closed

Description

@dgluszczyk

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When I try to replace FormGroup that is bound to template, disabled state of controls isn't updated.
I know, that I can use enable() and disable() methods, but in my case I'm generating complete FormGroups and I have to replace them.

For now I'm using workaround which crawls through whole AbstractControls tree and runs enable() and disable() methods but I believe it should be fixed in better way inside framework.

Expected behavior

Properly refreshed DOM when I toggle control's state using new instance of FormGroup.

Minimal reproduction of the problem with instructions

  1. Open related plunker: https://plnkr.co/edit/XSp2RhwBEEPylQub8W0L?p=preview
  2. Click on 'Two enabled fields' button. Title select hasn't changed state to enabled.
  3. Click on 'Two disabled fields' button. Name input hasn't changed state to disabled.

After each step value and state are updated inside connected FormControl (printed values) but change of disabled/enabled state is not propagated to DOM.

I created second plunker with one small change, I'm binding controls using [formControl] instead of formControlName and it behaves slightly different: it hasn't got any problems with switching state to disabled but it can't return to enabled state. Link: http://plnkr.co/edit/Xipc02DXwcv5y5gPmexo?p=preview

What is the motivation / use case for changing the behavior?

I need a clean way to replace FormGroups containing FormControls with disabled/enabled DOM state that corresponds to FormControl state.

Environment


Angular version: 4.3.0-beta.0

Browser:
- [x] Chrome (desktop) version 59.0.3071.115
- [x] Firefox version 54.0.1
- [x] IE version 11
 
For Tooling issues:
- Node version: v6.9.5
- Platform:  Windows

Activity

  1. TheRemjx01 commented on Aug 3, 2017

    @TheRemjx01

    I have also got troubled with this issue also. Is it fixed?

  2. dzonatan commented on Aug 16, 2017

    @dzonatan
    Contributor

    Duplicate of #17806.
    And fix is ready #18575

  3. kara commented on Dec 12, 2017

    @kara
    Contributor

    Yeah, looks like a duplicate of the bug tracked here #17806

  4. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions