Skip to content

Commit 6677d80

Browse files
committed
fix(datetime): ngModel always returns a string
1 parent 4c8efc2 commit 6677d80

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/components/datetime/datetime.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Form } from '../../util/form';
99
import { BaseInput } from '../../util/base-input';
1010
import { Item } from '../item/item';
1111
import { deepCopy, isBlank, isPresent, isArray, isString, assert, clamp } from '../../util/util';
12-
import { dateValueRange, renderDateTime, renderTextFormat, convertFormatToKey, getValueFromFormat, parseTemplate, parseDate, updateDate, DateTimeData, daysInMonth, dateSortValue, dateDataSortValue, LocaleData } from '../../util/datetime-util';
12+
import { dateValueRange, renderDateTime, renderTextFormat, convertDataToISO, convertFormatToKey, getValueFromFormat, parseTemplate, parseDate, updateDate, DateTimeData, daysInMonth, dateSortValue, dateDataSortValue, LocaleData } from '../../util/datetime-util';
1313

1414
/**
1515
* @name DateTime
@@ -267,14 +267,13 @@ import { dateValueRange, renderDateTime, renderTextFormat, convertFormatToKey, g
267267
providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: DateTime, multi: true } ],
268268
encapsulation: ViewEncapsulation.None,
269269
})
270-
export class DateTime extends BaseInput<DateTimeData|string> implements AfterViewInit, ControlValueAccessor, OnDestroy {
270+
export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit, ControlValueAccessor, OnDestroy {
271271

272272
_text: string = '';
273273
_min: DateTimeData;
274274
_max: DateTimeData;
275275
_locale: LocaleData = {};
276276
_picker: Picker;
277-
_internalValue: DateTimeData = {};
278277

279278
/**
280279
* @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
440439
/**
441440
* @hidden
442441
*/
443-
_inputReset() {
444-
this._internalValue = {};
445-
}
446-
447-
/**
448-
* @hidden
449-
*/
450-
_inputCheckHasValue(val: any) {
451-
updateDate(this._internalValue, val);
452-
super._inputCheckHasValue(val);
442+
_inputNormalize(val: any): DateTimeData {
443+
updateDate(this._value, val);
444+
return this._value;
453445
}
454446

455447
/**
@@ -474,6 +466,13 @@ export class DateTime extends BaseInput<DateTimeData|string> implements AfterVie
474466
return this.value;
475467
}
476468

469+
/**
470+
* @hidden
471+
*/
472+
_inputNgModelEvent(): any {
473+
return convertDataToISO(this.value);
474+
}
475+
477476
@HostListener('click', ['$event'])
478477
_click(ev: UIEvent) {
479478
// 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
758757
* @hidden
759758
*/
760759
getValue(): DateTimeData {
761-
return this._internalValue;
760+
return this._value;
762761
}
763762

764763
/**

src/util/base-input.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
146146
let normalized;
147147
if (val === null) {
148148
normalized = deepCopy(this._defaultValue);
149-
this._inputReset();
150149
} else {
151150
normalized = this._inputNormalize(val);
152151
}
@@ -240,7 +239,7 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
240239
* @hidden
241240
*/
242241
private onChange() {
243-
this._onChanged && this._onChanged(this._value);
242+
this._onChanged && this._onChanged(this._inputNgModelEvent());
244243
this._onTouched && this._onTouched();
245244
}
246245

@@ -291,11 +290,6 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
291290
*/
292291
initFocus() { }
293292

294-
/**
295-
* @hidden
296-
*/
297-
_inputReset() { }
298-
299293
/**
300294
* @hidden
301295
*/
@@ -317,6 +311,14 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
317311
return this;
318312
}
319313

314+
/**
315+
* @hidden
316+
*/
317+
_inputNgModelEvent(): any {
318+
return this._value;
319+
}
320+
321+
320322
/**
321323
* @hidden
322324
*/

0 commit comments

Comments
 (0)