Skip to content

Commit

Permalink
fix(datetime): Fix floating label with empty ion-datetime (#11552)
Browse files Browse the repository at this point in the history
Fixes #11547
  • Loading branch information
imgx64 authored and manucorporat committed May 8, 2017
1 parent 5fbca0e commit 5a895bb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/datetime/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PickerColumn } from '../picker/picker-options';
import { Form } from '../../util/form';
import { BaseInput } from '../../util/base-input';
import { Item } from '../item/item';
import { deepCopy, isBlank, isPresent, isArray, isString, assert, clamp } from '../../util/util';
import { deepCopy, isBlank, isPresent, isArray, isObject, isString, assert, clamp } from '../../util/util';
import { dateValueRange, renderDateTime, renderTextFormat, convertDataToISO, convertFormatToKey, getValueFromFormat, parseTemplate, parseDate, updateDate, DateTimeData, daysInMonth, dateSortValue, dateDataSortValue, LocaleData } from '../../util/datetime-util';

/**
Expand Down Expand Up @@ -760,6 +760,16 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterContentIni
return this._value;
}

/**
* @hidden
*/
hasValue(): boolean {
const val = this._value;
return isPresent(val)
&& isObject(val)
&& Object.keys(val).length > 0;
}

/**
* @hidden
*/
Expand Down
14 changes: 14 additions & 0 deletions src/components/datetime/test/datetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,20 @@ describe('DateTime', () => {

});

describe('hasValue', () => {

it('should return false if value is not set, and return true if value is set', zoned(() => {
expect(datetime.hasValue()).toEqual(false);

datetime.setValue('1994-12-15T13:47:20.789Z');
expect(datetime.hasValue()).toEqual(true);

datetime.setValue('');
expect(datetime.hasValue()).toEqual(false);
}));

});

var datetime: DateTime;
var picker: Picker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<ion-datetime displayFormat="D MMM YYYY" [(ngModel)]="floating2"></ion-datetime>
</ion-item>

<ion-item>
<ion-label floating>Floating</ion-label>
<ion-datetime [(ngModel)]="floating3"></ion-datetime>
</ion-item>

<ion-item>
<ion-label fixed>Fixed</ion-label>
<ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="fixed1"></ion-datetime>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class RootPage {
stacked2 = '1994-12-15T13:47:20.789';
floating1 = '1995-04-15';
floating2 = '1995-04-15';
floating3 = '';
fixed1 = '2002-09-23T15:03:46.789';
fixed2 = '2002-09-23T15:03:46.789';
inline1 = '2005-06-17T11:06Z';
Expand Down

0 comments on commit 5a895bb

Please sign in to comment.