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

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

Open

Description

@scottopherson

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/

Activity

  1. caitp commented on Mar 19, 2014

    @caitp
    Contributor

    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

  2. scottopherson commented on Mar 19, 2014

    @scottopherson
    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.

  3. added this to the milestone on Mar 20, 2014
  4. tkrotoff commented on Jun 17, 2015

    @tkrotoff

    +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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions