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.
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
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.
Most helpful comment
What if we want our input to be empty but setting picker to the current date ?