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

ng-invalid class is being added when required is set to false or null #5527

Closed
williamdstuart opened this issue Dec 1, 2015 · 8 comments
Closed

Comments

@williamdstuart
Copy link

@williamdstuart williamdstuart commented Dec 1, 2015

When binding the required DOM property of an input element, the ng-invalid class is always added.

<input type="text" [required]="false" #x [(ng-model)]="title"></input>{{ x.required + "-" + x.className }}

<input type="text" [required]="true" #y [(ng-model)]="title"></input>{{ y.required + "-" + y.className }}
@greg-md
Copy link

@greg-md greg-md commented Jan 13, 2016

In beta.1 remains the same problem!

If element is not required, or checkbox is not selected, you get invalid in ngForm.

@slintes
Copy link

@slintes slintes commented Feb 16, 2016

Hi, I have the same problem, I'm setting required and readonly based on a checkbox value, see this example:

http://plnkr.co/edit/XM8QTwkr3B4nzc40gEpx?p=preview

@zoechi
Copy link
Contributor

@zoechi zoechi commented Feb 17, 2016

Boolean properties are only removed on null, not on false

[required]="truthy ? true : null" (where `true` is any value other than `null`/`undefined`)
@williamdstuart
Copy link
Author

@williamdstuart williamdstuart commented Mar 16, 2016

@zoechi I tried both of the statements below, and the ng-invalid class is still added.

<input type="text" [required]="null" #x [(ngModel)]="title" />{{ x.required + "-" + x.className }}

<input type="text" [required]="1 === 2 ? true : null" #x [(ngModel)]="title" />{{ x.required + "-" + x.className }}
@williamdstuart williamdstuart changed the title ng-invalid class is being added when required is set to false ng-invalid class is being added when required is set to false or null Mar 16, 2016
@Celebes
Copy link

@Celebes Celebes commented Apr 19, 2016

I have the same problem, I defined conditional required attribute in input: [required]="isRequired ? 'true' : null". Not setting isRequired makes required attribute not present, but css class ng-invalid is still added.

@johannesjo
Copy link

@johannesjo johannesjo commented Aug 18, 2016

This is probably related: The ng-valid-required class is applied initially when using ng-required.

See:
http://plnkr.co/edit/nqPhJkmag3AQdntFRbEN?p=preview
johannesjo/ng-fab-form#90

@pkozlowski-opensource
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource commented Aug 31, 2016

This should be fixed by 0b665c0

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 9, 2019

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 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.