mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 16:16:41 +08:00
refactor(datetime): update value and text on init and value change
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import { Component, CssClassMap, Event, EventEmitter, Prop, PropDidChange } from '@stencil/core';
|
import { Component, CssClassMap, Event, EventEmitter, Prop, PropDidChange, State } from '@stencil/core';
|
||||||
|
|
||||||
import { convertFormatToKey, convertToArrayOfNumbers, convertToArrayOfStrings, dateDataSortValue, dateSortValue, DateTimeData, dateValueRange, daysInMonth, getValueFromFormat, LocaleData, parseDate, parseTemplate, renderTextFormat, renderDateTime } from './datetime-util';
|
import { convertFormatToKey, convertToArrayOfNumbers, convertToArrayOfStrings, dateDataSortValue, dateSortValue, DateTimeData, dateValueRange, daysInMonth, getValueFromFormat, LocaleData, parseDate, parseTemplate, renderTextFormat, renderDateTime, updateDate } from './datetime-util';
|
||||||
|
|
||||||
import { clamp, isBlank, isObject } from '../../utils/helpers';
|
import { clamp, isBlank, isObject } from '../../utils/helpers';
|
||||||
|
|
||||||
@ -259,12 +259,13 @@ export class DateTime {
|
|||||||
private labelId: string;
|
private labelId: string;
|
||||||
private picker: Picker;
|
private picker: Picker;
|
||||||
|
|
||||||
text: any;
|
|
||||||
locale: LocaleData = {};
|
locale: LocaleData = {};
|
||||||
dateTimeMin: DateTimeData = {};
|
dateTimeMin: DateTimeData = {};
|
||||||
dateTimeMax: DateTimeData = {};
|
dateTimeMax: DateTimeData = {};
|
||||||
dateTimeValue: DateTimeData = {};
|
dateTimeValue: DateTimeData = {};
|
||||||
|
|
||||||
|
@State() text: any;
|
||||||
|
|
||||||
@Prop({ connect: 'ion-picker-controller' }) pickerCtrl: PickerController;
|
@Prop({ connect: 'ion-picker-controller' }) pickerCtrl: PickerController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -413,11 +414,11 @@ export class DateTime {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
* Update the datetime text when the value changes
|
* Update the datetime value when the value changes
|
||||||
*/
|
*/
|
||||||
@PropDidChange('value')
|
@PropDidChange('value')
|
||||||
valueChanged() {
|
valueChanged() {
|
||||||
this.updateText();
|
this.updateValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -425,7 +426,7 @@ export class DateTime {
|
|||||||
*/
|
*/
|
||||||
@Event() ionCancel: EventEmitter;
|
@Event() ionCancel: EventEmitter;
|
||||||
|
|
||||||
protected ionViewDidLoad() {
|
protected ionViewWillLoad() {
|
||||||
// first see if locale names were provided in the inputs
|
// first see if locale names were provided in the inputs
|
||||||
// then check to see if they're in the config
|
// then check to see if they're in the config
|
||||||
// if neither were provided then it will use default English names
|
// if neither were provided then it will use default English names
|
||||||
@ -437,6 +438,15 @@ export class DateTime {
|
|||||||
dayShortNames: convertToArrayOfStrings(this.dayShortNames, 'dayShortNames')
|
dayShortNames: convertToArrayOfStrings(this.dayShortNames, 'dayShortNames')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.updateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
* Update the datetime text and datetime value
|
||||||
|
*/
|
||||||
|
updateValue() {
|
||||||
|
updateDate(this.dateTimeValue, this.value);
|
||||||
this.updateText();
|
this.updateText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user