mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 20:33:32 +08:00
fix(datetime): ngModel always returns a string
This commit is contained in:
@ -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<DateTimeData|string> implements AfterViewInit, ControlValueAccessor, OnDestroy {
|
||||
export class DateTime extends BaseInput<DateTimeData> 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<DateTimeData|string> 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<DateTimeData|string> 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<DateTimeData|string> implements AfterVie
|
||||
* @hidden
|
||||
*/
|
||||
getValue(): DateTimeData {
|
||||
return this._internalValue;
|
||||
return this._value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,7 +146,6 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
||||
let normalized;
|
||||
if (val === null) {
|
||||
normalized = deepCopy(this._defaultValue);
|
||||
this._inputReset();
|
||||
} else {
|
||||
normalized = this._inputNormalize(val);
|
||||
}
|
||||
@ -240,7 +239,7 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
||||
* @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<T> extends Ion implements CommonInput<T> {
|
||||
*/
|
||||
initFocus() { }
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
_inputReset() { }
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
@ -317,6 +311,14 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
_inputNgModelEvent(): any {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
|
Reference in New Issue
Block a user