mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +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 { BaseInput } from '../../util/base-input';
|
||||||
import { Item } from '../item/item';
|
import { Item } from '../item/item';
|
||||||
import { deepCopy, isBlank, isPresent, isArray, isString, assert, clamp } from '../../util/util';
|
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
|
* @name DateTime
|
||||||
@ -267,14 +267,13 @@ 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|string> implements AfterViewInit, ControlValueAccessor, OnDestroy {
|
export class DateTime extends BaseInput<DateTimeData> 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
|
||||||
@ -440,16 +439,9 @@ export class DateTime extends BaseInput<DateTimeData|string> implements AfterVie
|
|||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
_inputReset() {
|
_inputNormalize(val: any): DateTimeData {
|
||||||
this._internalValue = {};
|
updateDate(this._value, val);
|
||||||
}
|
return this._value;
|
||||||
|
|
||||||
/**
|
|
||||||
* @hidden
|
|
||||||
*/
|
|
||||||
_inputCheckHasValue(val: any) {
|
|
||||||
updateDate(this._internalValue, val);
|
|
||||||
super._inputCheckHasValue(val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -474,6 +466,13 @@ export class DateTime extends BaseInput<DateTimeData|string> implements AfterVie
|
|||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
*/
|
||||||
|
_inputNgModelEvent(): any {
|
||||||
|
return convertDataToISO(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
@HostListener('click', ['$event'])
|
@HostListener('click', ['$event'])
|
||||||
_click(ev: UIEvent) {
|
_click(ev: UIEvent) {
|
||||||
// do not continue if the click event came from a form submit
|
// 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
|
* @hidden
|
||||||
*/
|
*/
|
||||||
getValue(): DateTimeData {
|
getValue(): DateTimeData {
|
||||||
return this._internalValue;
|
return this._value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,7 +146,6 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
|||||||
let normalized;
|
let normalized;
|
||||||
if (val === null) {
|
if (val === null) {
|
||||||
normalized = deepCopy(this._defaultValue);
|
normalized = deepCopy(this._defaultValue);
|
||||||
this._inputReset();
|
|
||||||
} else {
|
} else {
|
||||||
normalized = this._inputNormalize(val);
|
normalized = this._inputNormalize(val);
|
||||||
}
|
}
|
||||||
@ -240,7 +239,7 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
|||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
private onChange() {
|
private onChange() {
|
||||||
this._onChanged && this._onChanged(this._value);
|
this._onChanged && this._onChanged(this._inputNgModelEvent());
|
||||||
this._onTouched && this._onTouched();
|
this._onTouched && this._onTouched();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,11 +290,6 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
|||||||
*/
|
*/
|
||||||
initFocus() { }
|
initFocus() { }
|
||||||
|
|
||||||
/**
|
|
||||||
* @hidden
|
|
||||||
*/
|
|
||||||
_inputReset() { }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
@ -317,6 +311,14 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
*/
|
||||||
|
_inputNgModelEvent(): any {
|
||||||
|
return this._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user