fix(datetime): ionChange/ngModel returns the correct value

This commit is contained in:
Manuel Mtz-Almeida
2017-04-27 18:35:37 +02:00
parent 505d27ad34
commit af394b5ef6
2 changed files with 36 additions and 11 deletions

View File

@ -267,13 +267,14 @@ import { dateValueRange, renderDateTime, renderTextFormat, convertFormatToKey, g
providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: DateTime, multi: true } ], providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: DateTime, multi: true } ],
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
}) })
export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit, ControlValueAccessor, OnDestroy { export class DateTime extends BaseInput<DateTimeData|string> implements AfterViewInit, ControlValueAccessor, OnDestroy {
_text: string = ''; _text: string = '';
_min: DateTimeData; _min: DateTimeData;
_max: DateTimeData; _max: DateTimeData;
_locale: LocaleData = {}; _locale: LocaleData = {};
_picker: Picker; _picker: Picker;
_internalValue: DateTimeData = {};
/** /**
* @input {string} The minimum datetime allowed. Value must be a date string * @input {string} The minimum datetime allowed. Value must be a date string
@ -436,6 +437,21 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
this._initialize(); this._initialize();
} }
/**
* @hidden
*/
_inputReset() {
this._internalValue = {};
}
/**
* @hidden
*/
_inputCheckHasValue(val: any) {
updateDate(this._internalValue, val);
super._inputCheckHasValue(val);
}
/** /**
* @hidden * @hidden
*/ */
@ -446,16 +462,16 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
/** /**
* @hidden * @hidden
*/ */
_inputNormalize(val: any): DateTimeData { _inputShouldChange(): boolean {
updateDate(this._value, val); return true;
return this._value;
} }
/** /**
* TODO: REMOVE THIS
* @hidden * @hidden
*/ */
_inputShouldChange(): boolean { _inputChangeEvent(): any {
return true; return this.value;
} }
@HostListener('click', ['$event']) @HostListener('click', ['$event'])
@ -742,7 +758,7 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
* @hidden * @hidden
*/ */
getValue(): DateTimeData { getValue(): DateTimeData {
return this._value; return this._internalValue;
} }
/** /**

View File

@ -143,9 +143,13 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
if (isUndefined(val)) { if (isUndefined(val)) {
return false; return false;
} }
const normalized = (val === null) let normalized;
? deepCopy(this._defaultValue) if (val === null) {
: this._inputNormalize(val); normalized = deepCopy(this._defaultValue);
this._inputReset();
} else {
normalized = this._inputNormalize(val);
}
const notUpdate = isUndefined(normalized) || !this._inputShouldChange(normalized); const notUpdate = isUndefined(normalized) || !this._inputShouldChange(normalized);
if (notUpdate) { if (notUpdate) {
@ -285,7 +289,12 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
/** /**
* @hidden * @hidden
*/ */
initFocus() {} initFocus() { }
/**
* @hidden
*/
_inputReset() { }
/** /**
* @hidden * @hidden