Skip to content

Commit

Permalink
fix(datetime): ionChange/ngModel returns the correct value
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 27, 2017
1 parent 505d27a commit af394b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
30 changes: 23 additions & 7 deletions src/components/datetime/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,14 @@ import { dateValueRange, renderDateTime, renderTextFormat, convertFormatToKey, g
providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: DateTime, multi: true } ],
encapsulation: ViewEncapsulation.None,
})
export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit, ControlValueAccessor, OnDestroy {
export class DateTime extends BaseInput<DateTimeData|string> 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 @@ -439,16 +440,23 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
/**
* @hidden
*/
_inputUpdated() {
this.updateText();
_inputReset() {
this._internalValue = {};
}

/**
* @hidden
*/
_inputCheckHasValue(val: any) {
updateDate(this._internalValue, val);
super._inputCheckHasValue(val);
}

/**
* @hidden
*/
_inputNormalize(val: any): DateTimeData {
updateDate(this._value, val);
return this._value;
_inputUpdated() {
this.updateText();
}

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

/**
* TODO: REMOVE THIS
* @hidden
*/
_inputChangeEvent(): any {
return this.value;
}

@HostListener('click', ['$event'])
_click(ev: UIEvent) {
// do not continue if the click event came from a form submit
Expand Down Expand Up @@ -742,7 +758,7 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterViewInit,
* @hidden
*/
getValue(): DateTimeData {
return this._value;
return this._internalValue;
}

/**
Expand Down
17 changes: 13 additions & 4 deletions src/util/base-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,13 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
if (isUndefined(val)) {
return false;
}
const normalized = (val === null)
? deepCopy(this._defaultValue)
: this._inputNormalize(val);
let normalized;
if (val === null) {
normalized = deepCopy(this._defaultValue);
this._inputReset();
} else {
normalized = this._inputNormalize(val);
}

const notUpdate = isUndefined(normalized) || !this._inputShouldChange(normalized);
if (notUpdate) {
Expand Down Expand Up @@ -285,7 +289,12 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
/**
* @hidden
*/
initFocus() {}
initFocus() { }

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

/**
* @hidden
Expand Down

0 comments on commit af394b5

Please sign in to comment.