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

Required doesn't work on date inputs in Chrome #11622

Closed
twhitbeck opened this issue Apr 16, 2015 · 2 comments
Closed

Required doesn't work on date inputs in Chrome #11622

twhitbeck opened this issue Apr 16, 2015 · 2 comments

Comments

@twhitbeck
Copy link
Contributor

For input[type=date] and input[type=month] (at least, that's all I've checked), in Chrome. If the required attribute is present, the ngModelController initially has the required error, which is expected. However, once a value is entered with the native date/month picker and subsequently cleared with the backspace key, only the month or date error is present.

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

Looking through the source is a bit confusing. There are comments in badInputChecker about email input types, but badInputChecker is not applied to input[type=email]. Maybe it was at one time.

To make things even more interesting, input[type=number] does not exhibit this behavior. Once the input is cleared, the validity.badInput property is set to false, whereas with the date inputs it is not. Is badInputChecker really doing us any good at this point?

Additionally, the native Chrome validator (which runs when the submit button is clicked) works correctly. A partially entered date or month will trigger a "Please enter a valid value." message whereas once it has been completely cleared Chrome says "Please fill out this field", even though in both cases the validity badInput property is true (once a date has been selected and then cleared).
Maybe this is just a browser bug.

@Narretz Narretz added this to the 1.4.x - jaracimrman-existence milestone Apr 20, 2015
@Narretz Narretz self-assigned this Apr 20, 2015
@Narretz
Copy link
Contributor

Narretz commented Jun 6, 2015

Yes, this seems to be a browser bug / odd spec behavior: http://plnkr.co/edit/ObAOxwgyubdM6KmKoWpq?p=preview

When you have picked a date, and then clear either year / month / day, the browser will fire an input event. When you clear the remaining fields, the event is not fired. This might be because after you clear the first field, the input value is already empty.
This could possibly remedied with listening to keydown, too.

@Narretz
Copy link
Contributor

Narretz commented Apr 9, 2016

We actually fixed this a while back. After clearing the input, the date / month error will disappear and required will return (as the input is now "empty" again).

@Narretz Narretz closed this as completed Apr 9, 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