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

input[type="date"] min/max as date objects #6754

Open
scottopherson opened this issue Mar 19, 2014 · 3 comments
Open

input[type="date"] min/max as date objects #6754

scottopherson opened this issue Mar 19, 2014 · 3 comments

Comments

@scottopherson
Copy link

The ability to use a Date object as the model for a date input is really convenient. As documented, min/max work when given a date string but is there any particular reason why the min/max attributes couldn't support date objects as well?

http://jsfiddle.net/va4kb/2/

@caitp
Copy link
Contributor

caitp commented Mar 19, 2014

This sort of thing has come up before, with regards for ng-true-value (among others) for checkboxes/etc. When using a single attribute, you don't want it to sometimes be a constant string, and sometimes a value to be parsed.

I don't necessarily think it's a problem to use a parsed value, particularly for dates, because I think it's unlikely people want to write out a constant date in their markup.

It may not be too late to change this API, I'm not sure. What do you think @tbosch, is that worthwhile? String-format dates could still be supported via min="'03/17/1988'" or something

@scottopherson
Copy link
Author

Yeah, I think it's fine to just use strings. I only brought it up because initially I had assumed that using date objects for min/max would work. After a couple minutes of trying to figure out why my example wasn't working, it wasn't until I took a closer look at the documentation that I realized my assumption was incorrect.

@lefos987 lefos987 added this to the Backlog milestone Mar 20, 2014
@btford btford removed the gh: issue label Aug 20, 2014
@tkrotoff
Copy link

+1, I have to write this:

<input type="date"
       ng-model="start"
       max="{{end != undefined ? end : '9999-01-01' | date: 'yyyy-MM-dd'}}">

<input type="date"
       ng-model="end"
       min="{{start != undefined ? start : '0001-01-01' | date: 'yyyy-MM-dd'}}">

This way it is compliant with Chrome datepicker: the user cannot select a date before/after min/max.

I would have expected to write:

<input type="date"
       ng-model="start"
       ng-max="end">

<input type="date"
       ng-model="end"
       ng-min="start">

with ng-min/max taking care of generating min/max attributes if the date is not undefined or null.

Same for <input type="time">, <input type="datetime-local">...

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

5 participants