Clarity: input type="date" : The value don't show up at start

Created on 18 Apr 2017  路  9Comments  路  Source: vmware/clarity

First, I would like to thank and congratulate the team for your work, Clarity is a pretty cool library.

[x] bug
[ ] feature request
[ ] enhancement

Expected behavior

I have an object with an existing date attribute in it, and I want it to be modified

<input type="date" name="dateToModify" [(ngModel)]="myObject.date">

I expect to show the actual date value and let me change it with the date picker.

Actual behavior

When a value already exists, the value don't appear in the input field. It only appears once I set it.

Reproduction of behavior


  • Include a link to the reproduction scenario you created by forking one of the Clarity Plunker Templates:


    Here's my Plunker.
    In the Plunker, I've set the date to a new Date (now), and we see that the date is well shown if I use an Angular2 date pipe, but it doesn't show in the input field.

Environment details

  • Angular version: 4.0.1

  • Clarity version: 0.9.0

  • OS and version: Linux Ubuntu 16.04

  • Browser: Chrome 57

duplicate

Most helpful comment

Hi @samdidos,
This is an Angular2 issue, not Clarity related. Many reports can be found on the topic.
The cleanest and easiest solution I've seen so far is to change the binding like this:

    `<input type="date"  [ngModel]="myDate | date:'yyyy-MM-dd'" 
                 (ngModelChange)="myDate = $event">`

Otherwise you have to manually parse the date you want to preset to the yyyy-MM-dd format, as the Angular component only recognises this format, not the generic Date object.

All 9 comments

Hi @samdidos,
This is an Angular2 issue, not Clarity related. Many reports can be found on the topic.
The cleanest and easiest solution I've seen so far is to change the binding like this:

    `<input type="date"  [ngModel]="myDate | date:'yyyy-MM-dd'" 
                 (ngModelChange)="myDate = $event">`

Otherwise you have to manually parse the date you want to preset to the yyyy-MM-dd format, as the Angular component only recognises this format, not the generic Date object.

Thanks @Jinnie For answering this. 馃槃

@Jinnie Thank you for the tip!

It works, thanks a lot! Can you help me on another similar matter? I would like the Clarity date picker to show the date in format "dd/mm/yyyy" instead of the default format "mm/dd/yyyy", is that possible?

@samdidos : There is no datepicker component in Clarity (yet). See #474

What you are likely seeing is the built-in Chrome datepicker that is tied to the date inputs.

See MDN article for more info on that

Ok thx a lot @mathisscott I haven't realised that!

@Jinnie Thanks alot!

Try this. Working fine
[(ngModel)]="admissionDetail.startDate">

Hi there 馃憢, this is an automated message. To help Clarity keep track of discussions, we automatically lock closed issues after 14 days. Please look for another open issue or open a new issue with updated details and reference this one as necessary.

Was this page helpful?
0 / 5 - 0 ratings