diff --git a/src/components/datetime/datetime.ts b/src/components/datetime/datetime.ts index d9e385c1cfb..27cf3a3b2cf 100644 --- a/src/components/datetime/datetime.ts +++ b/src/components/datetime/datetime.ts @@ -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'; /** @@ -760,6 +760,16 @@ export class DateTime extends BaseInput implements AfterContentIni return this._value; } + /** + * @hidden + */ + hasValue(): boolean { + const val = this._value; + return isPresent(val) + && isObject(val) + && Object.keys(val).length > 0; + } + /** * @hidden */ diff --git a/src/components/datetime/test/datetime.spec.ts b/src/components/datetime/test/datetime.spec.ts index 802e74d0bde..235ed4b7ebc 100644 --- a/src/components/datetime/test/datetime.spec.ts +++ b/src/components/datetime/test/datetime.spec.ts @@ -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; diff --git a/src/components/datetime/test/labels/pages/root-page/root-page.html b/src/components/datetime/test/labels/pages/root-page/root-page.html index 3bebd4cc460..0248e2c6b44 100644 --- a/src/components/datetime/test/labels/pages/root-page/root-page.html +++ b/src/components/datetime/test/labels/pages/root-page/root-page.html @@ -29,6 +29,11 @@ + + Floating + + + Fixed diff --git a/src/components/datetime/test/labels/pages/root-page/root-page.ts b/src/components/datetime/test/labels/pages/root-page/root-page.ts index 0d1cc6c7a29..089491b6cdd 100644 --- a/src/components/datetime/test/labels/pages/root-page/root-page.ts +++ b/src/components/datetime/test/labels/pages/root-page/root-page.ts @@ -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';