diff --git a/src/components/datetime/datetime.ts b/src/components/datetime/datetime.ts index 865f1c29fe1..fa492838fec 100644 --- a/src/components/datetime/datetime.ts +++ b/src/components/datetime/datetime.ts @@ -9,7 +9,7 @@ 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 { dateValueRange, renderDateTime, renderTextFormat, convertFormatToKey, getValueFromFormat, parseTemplate, parseDate, updateDate, DateTimeData, daysInMonth, dateSortValue, dateDataSortValue, LocaleData } from '../../util/datetime-util'; +import { dateValueRange, renderDateTime, renderTextFormat, convertDataToISO, convertFormatToKey, getValueFromFormat, parseTemplate, parseDate, updateDate, DateTimeData, daysInMonth, dateSortValue, dateDataSortValue, LocaleData } from '../../util/datetime-util'; /** * @name DateTime @@ -267,14 +267,13 @@ import { dateValueRange, renderDateTime, renderTextFormat, convertFormatToKey, g providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: DateTime, multi: true } ], encapsulation: ViewEncapsulation.None, }) -export class DateTime extends BaseInput implements AfterViewInit, ControlValueAccessor, OnDestroy { +export class DateTime extends BaseInput implements AfterViewInit, ControlValueAccessor, OnDestroy { _text: string = ''; _min: DateTimeData; _max: DateTimeData; _locale: LocaleData = {}; _picker: Picker; - _internalValue: DateTimeData = {}; /** * @input {string} The minimum datetime allowed. Value must be a date string @@ -440,16 +439,9 @@ export class DateTime extends BaseInput implements AfterVie /** * @hidden */ - _inputReset() { - this._internalValue = {}; - } - - /** - * @hidden - */ - _inputCheckHasValue(val: any) { - updateDate(this._internalValue, val); - super._inputCheckHasValue(val); + _inputNormalize(val: any): DateTimeData { + updateDate(this._value, val); + return this._value; } /** @@ -474,6 +466,13 @@ export class DateTime extends BaseInput implements AfterVie return this.value; } + /** + * @hidden + */ + _inputNgModelEvent(): any { + return convertDataToISO(this.value); + } + @HostListener('click', ['$event']) _click(ev: UIEvent) { // do not continue if the click event came from a form submit @@ -758,7 +757,7 @@ export class DateTime extends BaseInput implements AfterVie * @hidden */ getValue(): DateTimeData { - return this._internalValue; + return this._value; } /** diff --git a/src/util/base-input.ts b/src/util/base-input.ts index a71e6e2c8c9..55427deb878 100644 --- a/src/util/base-input.ts +++ b/src/util/base-input.ts @@ -146,7 +146,6 @@ export class BaseInput extends Ion implements CommonInput { let normalized; if (val === null) { normalized = deepCopy(this._defaultValue); - this._inputReset(); } else { normalized = this._inputNormalize(val); } @@ -240,7 +239,7 @@ export class BaseInput extends Ion implements CommonInput { * @hidden */ private onChange() { - this._onChanged && this._onChanged(this._value); + this._onChanged && this._onChanged(this._inputNgModelEvent()); this._onTouched && this._onTouched(); } @@ -291,11 +290,6 @@ export class BaseInput extends Ion implements CommonInput { */ initFocus() { } - /** - * @hidden - */ - _inputReset() { } - /** * @hidden */ @@ -317,6 +311,14 @@ export class BaseInput extends Ion implements CommonInput { return this; } + /** + * @hidden + */ + _inputNgModelEvent(): any { + return this._value; + } + + /** * @hidden */