mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
fix(datetime): ionChange/ngModel returns the correct value
This commit is contained in:
@ -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<DateTimeData> implements AfterViewInit, ControlValueAccessor, OnDestroy {
|
||||
export class DateTime extends BaseInput<DateTimeData|string> 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<DateTimeData> 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<DateTimeData> 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<DateTimeData> implements AfterViewInit,
|
||||
* @hidden
|
||||
*/
|
||||
getValue(): DateTimeData {
|
||||
return this._value;
|
||||
return this._internalValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,9 +143,13 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
||||
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<T> extends Ion implements CommonInput<T> {
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
initFocus() {}
|
||||
initFocus() { }
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
_inputReset() { }
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
|
Reference in New Issue
Block a user