Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

input type=date .ng-valid-date stays after reset #13587

Closed
ghost opened this issue Dec 18, 2015 · 5 comments
Closed

input type=date .ng-valid-date stays after reset #13587

ghost opened this issue Dec 18, 2015 · 5 comments

Comments

@ghost
Copy link

ghost commented Dec 18, 2015

Hello,

When I use Google Chrome with the input type date, there a cross that allow to reset the date.

I don't know if this is a bug or not since I'm very new to Angular but:

When I load the page, with the date set by the model to null
date1

When I set the day, month and year it has the .ng-valid-date class
date2

When I click on this cross, it has still the .ng-valid-date class but it's null again
date3

@Narretz
Copy link
Contributor

Narretz commented Dec 19, 2015

Yes, that looks like a bug. Thanks for reporting.

@gkalpak
Copy link
Member

gkalpak commented Dec 21, 2015

It seems that when the field is empty the field-type-specific class is not affected.

E.g. the same happens when clearing the date by deleting/unsetting each part (day, month, year).
In that case, the field is empty and valid, but the ng-invalid-date is still on the element.

@Narretz Narretz self-assigned this Jan 2, 2016
@Narretz
Copy link
Contributor

Narretz commented Jan 2, 2016

This is actually an issue for all validators (even though date input does the validation inside $parsers with parseError). Validators can only return true or false, and if the input is empty, they return true. Basically, there's no extra flag for the emptiness of an input. So any validator that is applied to an empty input will return true.
This probably not an issue for most people, because I assume most developers use styles for invalid classes, not for valid classes. Otherwise I can't explain why this issue hasn't been raised before. In 1.5, you can use the ng-not-empty class in conjunction with the valid classes, so that your styles etc. only appear when there's input in your inputs.
@gkalpak do you think we should fix this behavior?
We could fix this with having validators return a third type for when the validation is undefined / doesn't apply.

@Narretz Narretz removed their assignment Jan 2, 2016
@Narretz Narretz modified the milestones: 1.6.x, 1.5.x - migration-facilitation Jan 2, 2016
@gkalpak
Copy link
Member

gkalpak commented Jan 22, 2016

Revisiting this, I think the behavior described in OP's post is as expected for when clearing the field. Currently, there is the problem of not running the validation when partially editing the date fields, but it will be fixed with #12902#13886.

The only thing that is a little weird (and probably needs further investigation) is the fact that (unlike other validators) the date validator does not initially add the ng-valid-date class when the field is empty. This is inconsistent, because other validators that I tried do set their valid classes immediatelly, but since the overall ng-valid class is set correctly, I am not too concerned about this.
I don't think the specific validator classes are that useful or that many people rely on them for something.

@gkalpak
Copy link
Member

gkalpak commented Dec 23, 2016

Closing as a duplicate of #14740 (since that one has more discussion).

Note to self, wrt:

The only thing that is a little weird (and probably needs further investigation) is the fact that (unlike other validators) the date validator does not initially add the ng-valid-date class when the field is empty.

The difference with other fields (e.g. email, url etc) is that date does not have a date validator; it relies on the default $$parserName validator (also named date). Other fields have $validators that match $$parserName.

@gkalpak gkalpak closed this as completed Dec 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants