Skip to content

Commit

Permalink
fix(datetime): ngModel always returns a string
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 27, 2017
1 parent 4c8efc2 commit 6677d80
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
27 changes: 13 additions & 14 deletions src/components/datetime/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -758,7 +757,7 @@ export class DateTime extends BaseInput<DateTimeData|string> implements AfterVie
* @hidden
*/
getValue(): DateTimeData {
return this._internalValue;
return this._value;
}

/**
Expand Down
16 changes: 9 additions & 7 deletions src/util/base-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}

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

/**
* @hidden
*/
_inputReset() { }

/**
* @hidden
*/
Expand All @@ -317,6 +311,14 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
return this;
}

/**
* @hidden
*/
_inputNgModelEvent(): any {
return this._value;
}


/**
* @hidden
*/
Expand Down

0 comments on commit 6677d80

Please sign in to comment.