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

Fix: Input/Radio should be disabled when disabling the formcontrol #1242

Closed
wants to merge 4 commits into from
Closed

Fix: Input/Radio should be disabled when disabling the formcontrol #1242

wants to merge 4 commits into from

Conversation

Sabartius
Copy link

@Sabartius Sabartius commented Sep 15, 2016

Fixes #1171 for Input-Elements and Radio

@jelbourn @kara I've tried to repair the checkbox too, but i couldn't test it properly.
My test for the checkbox only worked, when i deleted the ChangeDetectionStrategy.OnPush from the Component, but thats not the solution i wanted to push.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 15, 2016
@Sabartius
Copy link
Author

Sabartius commented Sep 15, 2016

I tried the checkbox in an demo app and it disables & enables successfully. So it's only something with the change-detection in the testenvironment that's not working as expected.

@Sabartius Sabartius changed the title Fix: Input should be disabled when disabling the formcontrol Fix: Input/Radio should be disabled when disabling the formcontrol Sep 15, 2016
formControl.disable();
fixture.detectChanges();

fixture.whenStable().then(() => {
Copy link
Member

@jelbourn jelbourn Sep 15, 2016

Choose a reason for hiding this comment

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

@kara, is using whenStable supposed to be necessary for changing disabled state?
(here and elsewhere)

fixture.detectChanges();
fixture.whenStable().then(() => {
expect(inputElement.disabled).toBeTruthy('InputElement should be disabled');
expect(mdInput.disabled).toBeTruthy('Component should be disabled');
Copy link
Member

Choose a reason for hiding this comment

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

Huh, I had no idea you could pass a message like that.

Copy link
Author

Choose a reason for hiding this comment

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

It helps alot when looking for errors :)

fixture = TestBed.createComponent(RadioGroupWithReactiveForms);
fixture.detectChanges();

fixture.whenStable().then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need a whenStable in the beforeEach?

Copy link
Author

Choose a reason for hiding this comment

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

Didn't need that one, got removed in the next commit

radioInputs.forEach(input =>
expect(input.disabled).toBeTruthy(input.value + ' should be disabled'));
nativeRadioInputs.forEach(input =>
expect(input.disabled).toBeTruthy('Native ' + input.id + ' should be disabled'));
Copy link
Member

Choose a reason for hiding this comment

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

You can use template strings for these messages

Copy link
Author

Choose a reason for hiding this comment

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

Done

@jelbourn
Copy link
Member

@kara should take a look

@Sabartius
Copy link
Author

@jelbourn @kara what's your opinion on the checkbox? I can push a solution, even a test for the checkbox, but because of the changedetection-strategy of the checkbox-component i cannot test if the underlying input-element gets disabled, only that the component gets disabled.

@jelbourn
Copy link
Member

@Sabartius can you push the change for checkbox including the failing test? We can take a look at see what needs to be changed.

@Sabartius
Copy link
Author

@jelbourn Pushed it. Hope you can find the problem :)

@jelbourn jelbourn assigned tinayuangao and unassigned kara Nov 3, 2016
@jelbourn
Copy link
Member

jelbourn commented Nov 3, 2016

@tinayuangao can you follow up on this?

@jelbourn
Copy link
Member

Superseded by #1750

@jelbourn jelbourn closed this Nov 17, 2016
@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[input @alpha.8-1] Setting bound FormControl to disabled causes valueAccessor.setDisabledState error
5 participants