From af394b5ef69cfd42e0398f50e2fda364ea9235a3 Mon Sep 17 00:00:00 2001 From: Manuel Mtz-Almeida Date: Thu, 27 Apr 2017 18:35:37 +0200 Subject: [PATCH] fix(datetime): ionChange/ngModel returns the correct value --- src/components/datetime/datetime.ts | 30 ++++++++++++++++++++++------- src/util/base-input.ts | 17 ++++++++++++---- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/components/datetime/datetime.ts b/src/components/datetime/datetime.ts index aa5a65799a..865f1c29fe 100644 --- a/src/components/datetime/datetime.ts +++ b/src/components/datetime/datetime.ts @@ -267,13 +267,14 @@ 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 @@ -436,6 +437,21 @@ export class DateTime extends BaseInput implements AfterViewInit, this._initialize(); } + /** + * @hidden + */ + _inputReset() { + this._internalValue = {}; + } + + /** + * @hidden + */ + _inputCheckHasValue(val: any) { + updateDate(this._internalValue, val); + super._inputCheckHasValue(val); + } + /** * @hidden */ @@ -446,16 +462,16 @@ export class DateTime extends BaseInput implements AfterViewInit, /** * @hidden */ - _inputNormalize(val: any): DateTimeData { - updateDate(this._value, val); - return this._value; + _inputShouldChange(): boolean { + return true; } /** + * TODO: REMOVE THIS * @hidden */ - _inputShouldChange(): boolean { - return true; + _inputChangeEvent(): any { + return this.value; } @HostListener('click', ['$event']) @@ -742,7 +758,7 @@ export class DateTime extends BaseInput implements AfterViewInit, * @hidden */ getValue(): DateTimeData { - return this._value; + return this._internalValue; } /** diff --git a/src/util/base-input.ts b/src/util/base-input.ts index 3e9b07314e..a71e6e2c8c 100644 --- a/src/util/base-input.ts +++ b/src/util/base-input.ts @@ -143,9 +143,13 @@ export class BaseInput extends Ion implements CommonInput { if (isUndefined(val)) { return false; } - const normalized = (val === null) - ? deepCopy(this._defaultValue) - : this._inputNormalize(val); + let normalized; + if (val === null) { + normalized = deepCopy(this._defaultValue); + this._inputReset(); + } else { + normalized = this._inputNormalize(val); + } const notUpdate = isUndefined(normalized) || !this._inputShouldChange(normalized); if (notUpdate) { @@ -285,7 +289,12 @@ export class BaseInput extends Ion implements CommonInput { /** * @hidden */ - initFocus() {} + initFocus() { } + + /** + * @hidden + */ + _inputReset() { } /** * @hidden