Ionic-framework: Feature Request : DateTime Component - Option to set current time as default value for picker

Created on 5 Sep 2016  路  5Comments  路  Source: ionic-team/ionic-framework

Short description of the problem:

The DateTime Component allows to create a simple input component for date and time inputs. It would be nice, if there was an option to set the current time as default value for the picker.

In many cases it would be useful, if the default value of the picker was not 1. January 2016 but the current date of the day. With this people could fill out the form even faster, same applies to time inputs.

What behavior are you expecting?

Add some sort of attribute to the datetime component which allows to set the default value of the picker to the current time.

<ion-item>
  <ion-label>Date</ion-label>
  <ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="myDate" useCurrentTimeAsDefaultValue="true"></ion-datetime>
</ion-item>

Which Ionic Version?
ionic 2.00-beta 11

Most helpful comment

What if we want our input to be empty but setting picker to the current date ?

All 5 comments

You can/should initialize your model to an ISO 8601 datetime formatted value.

JavaScript's Date object has a .toISOString() function. So in your case, to get current time, just initialize myDate in your component to

myDate = new Date().toISOString();

@kshaaban- Thanks a lot, this solves my case perfectly. Sorry for asking such an simple question. Will close this issue then.

What if we want our input to be empty but setting picker to the current date ?

+1 on @charlesen's comment. This is a situation I'm currently facing which doesn't seem to be catered for..

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daveshirman picture daveshirman  路  3Comments

SebastianGiro picture SebastianGiro  路  3Comments

Nick-The-Uncharted picture Nick-The-Uncharted  路  3Comments

alan-agius4 picture alan-agius4  路  3Comments

manucorporat picture manucorporat  路  3Comments