Skip to content

fix(forms): Call setDisabledState in in reactive directives when appropriate - #35311

Closed
jermowery wants to merge 1 commit into
angular:masterfrom
jermowery:fixFormControlDisable
Closed

jermowery wants to merge 1 commit into
angular:masterfrom
jermowery:fixFormControlDisable

Conversation

@jermowery

Copy link
Copy Markdown
Contributor

When a CVA is added a form and that CVA implements setDisabledState the
reactive form directives should call setDisabledState with true when the
FormControl is disabled and false when it is enabled. Currently,
setDisabledState is only called when the FormControl is disabled.

Fixes #35309

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • [ x] Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

setDisabledState when adding a control to a form is called with true with the FormControl is disabled and not called when the FormControl is enabled.

Issue Number: #35309

What is the new behavior?

setDisabledState is called when adding a control to a form with false when the FormControl is enabled and true with the FormControl is disabled.

Does this PR introduce a breaking change?

  • Yes
  • [x ] No

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jermowery thanks for creating a PR! 👍 I left a couple nits, please have a look.

It looks like this PR also introduces behavior change for Forms, where setDisabledState is called in situations where it was not called before. Could you please try to run Global TAP with this change to see if there are targets that might be potentially affected?

Thank you.

@AndrewKushnir AndrewKushnir added area: forms action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Feb 11, 2020
@ngbot ngbot Bot added this to the needsTriage milestone Feb 11, 2020
@jermowery

Copy link
Copy Markdown
Contributor Author

It looks like this PR also introduces behavior change for Forms, where setDisabledState is called in situations where it was not called before. Could you please try to run Global TAP with this change to see if there are targets that might be potentially affected?

There are 3 specs failing as a result of this change. 2 of which are in my own codebase. I will put together a CL that can be patched with the fixes for the Angular caretaker doing the sync

appropriate

When a CVA is added a form and that CVA implements setDisabledState the
reactive form directives should call setDisabledState with true when the
FormControl is disabled and false when it is enabled. Currently,
setDisabledState is only called when the FormControl is disabled.

Fixes #35309

Fix based on comments
@AndrewKushnir
AndrewKushnir requested a review from kara February 11, 2020 02:20
@jermowery
jermowery requested review from AndrewKushnir and removed request for kara February 11, 2020 02:22

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for additional changes @jermowery!

There are 3 specs failing as a result of this change. 2 of which are in my own codebase. I will put
together a CL that can be patched with the fixes for the Angular caretaker doing the sync

Thanks for verifying this in g3 👍Given that there are some (minor) breakages, I'd like to ask @kara to have a look at this PR too, to make sure we assess the risks accordingly.

Thank you.

@jermowery

Copy link
Copy Markdown
Contributor Author

I just took another look at my Global TAP and it looks like there are more changes than anticipated. I will discuss with you all tomorrow

@sonukapoor

Copy link
Copy Markdown
Contributor

Hi @jermowery, I was working on a similar PR, but noticed that your PR already covers what I was going to change as well. Is there anything I can help with for this PR?

@jermowery

Copy link
Copy Markdown
Contributor Author

Unfortunately, this breaks a significant number of tests inside Google, and I don't have to bandwidth to fix them, so this PR is pretty much abandoned

@AndrewKushnir

Copy link
Copy Markdown
Contributor

FYI, potentially related PR #18575 and related (duplicate?) issue #17806.

@AndrewKushnir

Copy link
Copy Markdown
Contributor

Hi @jermowery, since this is a breaking change and it affects a lot of targets internally in google3, I was thinking if we should consider adding a config option similar to the warnOnNgModelWithFormControl one defined here. That should keep existing behavior, allow enabling new/corrected one and simplify the rollout of this change (make it incremental). WDYT?

@jermowery

Copy link
Copy Markdown
Contributor Author

That seems reasonable. Sadly I don't have the bandwidth right now to incorporate that change but feel free to adopt this PR if it is a priority

@sonukapoor

Copy link
Copy Markdown
Contributor

@jermowery / @AndrewKushnir I would be happy to make this change.

@grosch

grosch commented Jul 21, 2020

Copy link
Copy Markdown

What's the status of this being implemented?

@mohamed-gara

mohamed-gara commented Jul 29, 2020 •

Copy link
Copy Markdown

There is already this PR #20310. I think it's the same fix.

@Jakartoine

Copy link
Copy Markdown

@AndrewKushnir,

Sorry for disturbing you but do you have any update about this point?

To workaround this, I had to recreate a custom radio button component with an override on NG_VALUE_ACCESSOR.

Already 3 years since this bug has been discovered without any fix...

Thank you in advance

@AndrewKushnir

Copy link
Copy Markdown
Contributor

Hi @Jakartoine,

Unfortunately we don't have any updates on this issue at this moment.

The problem with the fix is that it requires a breaking change: it changes the behavior (to be more correct), but this affects existing apps since some of them rely on the current sequence of calls to the setDisabledState methods defined on CVAs. Running tests in Google's codebase indicated that the breaking change is quite severe and there is no easy way to auto-correct the code with schematic/migration. We have to come up with a migration strategy, such as introducing a flag (something like ReactiveFormsModule.withConfig({setDisabledStateBehavior: 'legacy' /* or 'new' */})) for apps to opt into using the "correct" behavior, wait for 1-2 major versions and only after that flip the flag to make "correct" behavior default. This work requires some planning and additional investigations and we didn't have a chance to prioritize this yet. We'll keep this PR updated once we have more info available.

Thank you.

@Jakartoine

Copy link
Copy Markdown

@AndrewKushnir

Alright, it sounds clearer now. Thank you for your response mate.

@angular-automatic-lock-bot

Copy link
Copy Markdown

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.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Mar 24, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: forms breaking changes cla: yes state: blocked target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FormControlDirective and FormControlName do not call setDisabledState on ControlValueAcessor instances when the CVA is added and is enabled

7 participants