Skip to content

Commit af394b5

Browse files
committed
fix(datetime): ionChange/ngModel returns the correct value
1 parent 505d27a commit af394b5

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

src/components/datetime/datetime.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ 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> implements AfterViewInit, ControlValueAccessor, OnDestroy {
270+
export class DateTime extends BaseInput<DateTimeData|string> implements AfterViewInit, ControlValueAccessor, OnDestroy {
271271

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

278279
/**
279280
* @input {string} The minimum datetime allowed. Value must be a date string
@@ -439,16 +440,23 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
439440
/**
440441
* @hidden
441442
*/
442-
_inputUpdated() {
443-
this.updateText();
443+
_inputReset() {
444+
this._internalValue = {};
445+
}
446+
447+
/**
448+
* @hidden
449+
*/
450+
_inputCheckHasValue(val: any) {
451+
updateDate(this._internalValue, val);
452+
super._inputCheckHasValue(val);
444453
}
445454

446455
/**
447456
* @hidden
448457
*/
449-
_inputNormalize(val: any): DateTimeData {
450-
updateDate(this._value, val);
451-
return this._value;
458+
_inputUpdated() {
459+
this.updateText();
452460
}
453461

454462
/**
@@ -458,6 +466,14 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
458466
return true;
459467
}
460468

469+
/**
470+
* TODO: REMOVE THIS
471+
* @hidden
472+
*/
473+
_inputChangeEvent(): any {
474+
return this.value;
475+
}
476+
461477
@HostListener('click', ['$event'])
462478
_click(ev: UIEvent) {
463479
// do not continue if the click event came from a form submit
@@ -742,7 +758,7 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
742758
* @hidden
743759
*/
744760
getValue(): DateTimeData {
745-
return this._value;
761+
return this._internalValue;
746762
}
747763

748764
/**

src/util/base-input.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
143143
if (isUndefined(val)) {
144144
return false;
145145
}
146-
const normalized = (val === null)
147-
? deepCopy(this._defaultValue)
148-
: this._inputNormalize(val);
146+
let normalized;
147+
if (val === null) {
148+
normalized = deepCopy(this._defaultValue);
149+
this._inputReset();
150+
} else {
151+
normalized = this._inputNormalize(val);
152+
}
149153

150154
const notUpdate = isUndefined(normalized) || !this._inputShouldChange(normalized);
151155
if (notUpdate) {
@@ -285,7 +289,12 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
285289
/**
286290
* @hidden
287291
*/
288-
initFocus() {}
292+
initFocus() { }
293+
294+
/**
295+
* @hidden
296+
*/
297+
_inputReset() { }
289298

290299
/**
291300
* @hidden

0 commit comments

Comments
 (0)