Skip to content

fix(slide-toggle): invalid required validator in template-driven forms #16547

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

Conversation

devversion
Copy link
Member

Currently using the slide-toggle in a form using template-driven forms causes
the slide-toggle to retrieve a wrong validator if the required attribute is set.

This is because by default @angular/forms uses an input validator
that ensures that the value is just defined. This is always the case for
a slide-toggle since the value is always true or false.

The solution to this problem is that we need to provide the checkbox validator
for required slide-toggle components. The checkbox validator from the forms
package ensures that the control is only valid if the slide-toggle is checked.

@devversion devversion added the target: patch This PR is targeted for the next patch release label Jul 17, 2019
@devversion devversion requested a review from crisbeto as a code owner July 17, 2019 08:53
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 17, 2019
Currently using the `slide-toggle` in a form using template-driven forms causes
the slide-toggle to retrieve a wrong validator if the `required` attribute is set.

This is because by default `@angular/forms` uses an input validator
that ensures that the value is just defined. This is always the case for
a slide-toggle since the value is always `true` or `false`.

The solution to this problem is that we need to provide the checkbox validator
for required slide-toggle components. The checkbox validator from the forms
package ensures that the control is only valid if the slide-toggle is checked.
@devversion devversion force-pushed the fix/slide-toggle-required-validator-template-forms branch from f6a5fd9 to 60a2cdf Compare July 17, 2019 09:16
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jul 17, 2019
@jelbourn
Copy link
Member

Going with target: patch for now, but we'll see if this ends up being breaking inside Google

@jelbourn jelbourn merged commit a415b52 into angular:master Jul 19, 2019
andrewseguin pushed a commit that referenced this pull request Jul 29, 2019
#16547)

Currently using the `slide-toggle` in a form using template-driven forms causes
the slide-toggle to retrieve a wrong validator if the `required` attribute is set.

This is because by default `@angular/forms` uses an input validator
that ensures that the value is just defined. This is always the case for
a slide-toggle since the value is always `true` or `false`.

The solution to this problem is that we need to provide the checkbox validator
for required slide-toggle components. The checkbox validator from the forms
package ensures that the control is only valid if the slide-toggle is checked.
@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 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants