Skip to content
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

Inputs are always reading the disabled state from the form control #5358

Closed
amcdnl opened this issue Jun 25, 2017 · 6 comments
Closed

Inputs are always reading the disabled state from the form control #5358

amcdnl opened this issue Jun 25, 2017 · 6 comments
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@amcdnl
Copy link
Contributor

amcdnl commented Jun 25, 2017

Bug, feature request, or proposal:

Inputs are always reading the disabled state from the form control.

What is the expected behavior?

The input would be disabled.

What is the current behavior?

The input is not being disabled

What are the steps to reproduce?

https://plnkr.co/edit/WRdgmjdwsLwy9Fx2XRqG?p=preview

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

2.0.0-beta.7

@jelbourn jelbourn added the P2 The issue is important to a large percentage of users, with a workaround label Jun 25, 2017
@jelbourn
Copy link
Member

@kara what is the right way for the disabled state to work here?

@amcdnl
Copy link
Contributor Author

amcdnl commented Jun 25, 2017

Note: Angular actually notifies you in the console...

It looks like you're using the disabled attribute with a reactive form directive. 
If you set disabled to true  when you set up this control in your component class, 
the disabled attribute will actually be set in the DOM for you. We recommend 
using this approach to avoid 'changed after checked' errors.
       
      Example: 
      form = new FormGroup({
        first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
        last: new FormControl('Drew', Validators.required)
      });

@julianobrasil
Copy link
Contributor

julianobrasil commented Jun 25, 2017

@amcdnl, shouldn't you be doing something like

(change)="stateCtrl.enabled ? stateCtrl.disable() : stateCtrl.enable()"

in the <md-slide-toggle> instead of trying to use the [disabled] attribute in the <input> (as adviced in the console, because it's a reactive form control)?

@willshowell
Copy link
Contributor

@amcdnl in addition, see @kara's comment here #2667 (comment)

In short, the behavior is right in that the control should always take precedence over the disabled property. Otherwise, if you disable the control programmatically without setting the disabled property (as is typical of reactive form pattern), the input will not pick up the new disabled state.

@kara
Copy link
Contributor

kara commented Jun 26, 2017

I can't get the plunker to load for some reason, but from the comments, it sounds like you have a disabled attribute with a reactive form control and have not used form control state (new FormControl({value: '', disabled: true})) or the imperative methods to enable/disable. If that is the case, the input is working as intended. Reactive form controls set the disabled attribute for you, so there's no reason to place it there manually.

@kara kara closed this as completed Jun 26, 2017
@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

No branches or pull requests

6 participants