Skip to content

Commit

Permalink
feat(datetime): add default picker value input
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Jaskólski committed Aug 18, 2017
1 parent 26b09f1 commit b87d212
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/datetime/datetime.ts
Expand Up @@ -319,6 +319,14 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterContentIni
*/
@Input() displayFormat: string;

/**
* @input {string} The default datetime selected in picker modal if field value is empty.
* Value must be a date string following the
* [ISO 8601 datetime format standard](https://www.w3.org/TR/NOTE-datetime),
* `1996-12-19`.
*/
@Input() pickerDefault: string;

/**
* @input {string} The format of the date and time picker columns the user selects.
* A datetime input can have one or many datetime parts, each getting their
Expand Down Expand Up @@ -596,7 +604,7 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterContentIni

// cool, we've loaded up the columns with options
// preselect the option for this column
const optValue = getValueFromFormat(this.getValue(), format);
const optValue = getValueFromFormat(this.getValueOrDefault(), format);
const selectedIndex = column.options.findIndex(opt => opt.value === optValue);
if (selectedIndex >= 0) {
// set the select index for this column's options
Expand Down Expand Up @@ -772,6 +780,18 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterContentIni
return this._value;
}

/**
* @hidden
*/
getValueOrDefault(): DateTimeData {
if (this.hasValue()) {
return this._value;
}
const _default = {};
updateDate(_default, this.pickerDefault);
return _default;
}

/**
* @hidden
*/
Expand Down
Expand Up @@ -77,6 +77,11 @@
<ion-datetime monthValues="6,7,8" yearValues="2014,2015" dayValues="01,02,03,04,05,06,08,09,10, 11, 12, 13, 14" displayFormat="DD/MMM/YYYY" [(ngModel)]="specificDaysMonthsYears"></ion-datetime>
</ion-item>

<ion-item>
<ion-label>Default value</ion-label>
<ion-datetime max="2100" pickerDefault="2017-08-06" [(ngModel)]="defaultValue"></ion-datetime>
</ion-item>

<p aria-hidden="true" padding>
<code>monthOnly: {{monthOnly}}</code><br>
<code>wwwInvented: {{wwwInvented}}</code><br>
Expand All @@ -88,6 +93,7 @@
<code>time: {{time}}</code><br>
<code>Leap year, summer months: {{leapYearsSummerMonths}}</code><br>
<code>Specific days/months/years: {{specificDaysMonthsYears}}</code><br>
<code>Default value: {{defaultValue}}</code><br>
</p>

<p>
Expand Down
Expand Up @@ -17,6 +17,7 @@ export class RootPage {
leapYearsSummerMonths = '';
convertedDate = '';
specificDaysMonthsYears = '';
defaultValue: any;

leapYearsArray = [2020, 2016, 2008, 2004, 2000, 1996];

Expand Down

0 comments on commit b87d212

Please sign in to comment.