Skip to content

mat-slide-toggle: does not always follow formGroup initialization state #8022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kdrvn opened this issue Oct 25, 2017 · 8 comments
Closed

mat-slide-toggle: does not always follow formGroup initialization state #8022

kdrvn opened this issue Oct 25, 2017 · 8 comments
Assignees
Labels
blocked This issue is blocked by some external factor, such as a prerequisite PR

Comments

@kdrvn
Copy link
Contributor

kdrvn commented Oct 25, 2017

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Given I have a form group with a slide toggle set as disabled: true
When recreating the form group with the slide toggle set as disabled: false
Then the slide toggle should be enabled.

Given I have a form group with a slide toggle set as disabled: false
When recreating the form group with the slide toggle set as disabled: true
Then the slide toggle should be disabled.

What is the current behavior?

After first form group initialization, the slide toggle state isn't affected by the disabled setting in subsequent form group initialization.

What are the steps to reproduce?

In an Angular component, with a formGroup:

this.formGroup = this.formBuilder.group({
  input: [{value: '', disabled: false}],
  slideToggle: [{value: '', disabled: false}]
});

And a form template:

<form class="example-form" [formGroup]="formGroup">
  <input matInput formControlName="input" />
  <mat-slide-toggle formControlName="slideToggle">Slide Toggle</mat-slide-toggle>
</form>

At any point during the lifetime of the component, recreate the form group but with a different disabled state for the controls:

this.formGroup = this.formBuilder.group({
  input: [{value: '', disabled: true}],
  slideToggle: [{value: '', disabled: true}]
});

The input will have correctly changed disabled state, however the slide toggle will not.

https://stackblitz.com/edit/angular-material2-issue-slide-toggle

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 4.4.6
Angular Material 2.0.0-beta.12
tested in Chrome

Is there anything else we should know?

Similar issues: #4774 (fix: #4797)

@kdrvn
Copy link
Contributor Author

kdrvn commented Oct 27, 2017

This issue is present for any custom form component in angular material.
Issue observed with:

  • checkbox,
  • datepicker,
  • radio button,
  • select,
  • slider,
  • slide toggle.

Stackblitz with all material form controls: https://stackblitz.com/edit/angular-material2-formgroup-issue

@willshowell
Copy link
Contributor

This sounds pretty similar to #6849. Note that using the .enable()/.disable() apis from FormControl do still work. The problem arises when you reassign the FormGroup.

I guess one of the differences is, in your all control example, the input/autocomplete/datepicker controls do get disabled, they just don't run change detection until you click on them. The other controls do not disable at all.

@jelbourn
Copy link
Member

@tinayuangao can you investigate this? @kara should be able to help with forms-related questions

@tinayuangao
Copy link
Contributor

@jelbourn
Copy link
Member

@tinayuangao is it working as intended, then?

@tinayuangao
Copy link
Contributor

Yes.
Disabling doesn't work yet with re-assigned form groups. Once forms support that our components implementing ControlValueAccessor will support it.

The input component support disabling because the input component read the disabled variable of ngControl.

@tinayuangao
Copy link
Contributor

Close this issue for now.

Please feel free to reopen when angular forms supports it.

@angular-automatic-lock-bot
Copy link

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 Sep 7, 2019
@mmalerba mmalerba added the blocked This issue is blocked by some external factor, such as a prerequisite PR label Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked This issue is blocked by some external factor, such as a prerequisite PR
Projects
None yet
Development

No branches or pull requests

5 participants