mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(time-picker): properly handle 0 on hour and minutes with valueChanged (#10460)
closes https://github.com/NativeScript/NativeScript/issues/10457
This commit is contained in:
@@ -165,8 +165,11 @@ minuteIntervalProperty.register(TimePickerBase);
|
||||
|
||||
export const minuteProperty = new Property<TimePickerBase, number>({
|
||||
name: 'minute',
|
||||
defaultValue: 0,
|
||||
// avoid defaultValue of 0 because it will prevent valueChanged from firing to initialize value due to it already matching defaultValue to start
|
||||
// sometimes user needs to set 0: https://github.com/NativeScript/NativeScript/issues/10457
|
||||
defaultValue: null,
|
||||
valueChanged: (picker, oldValue, newValue) => {
|
||||
newValue = newValue || 0;
|
||||
if (!isMinuteValid(newValue) || !isValidTime(picker)) {
|
||||
throw new Error(getErrorMessage(picker, 'minute', newValue));
|
||||
}
|
||||
@@ -179,8 +182,11 @@ minuteProperty.register(TimePickerBase);
|
||||
|
||||
export const hourProperty = new Property<TimePickerBase, number>({
|
||||
name: 'hour',
|
||||
defaultValue: 0,
|
||||
// avoid defaultValue of 0 because it will prevent valueChanged from firing to initialize value due to it already matching defaultValue to start
|
||||
// sometimes user needs to set 0: https://github.com/NativeScript/NativeScript/issues/10457
|
||||
defaultValue: null,
|
||||
valueChanged: (picker, oldValue, newValue) => {
|
||||
newValue = newValue || 0;
|
||||
if (!isHourValid(newValue) || !isValidTime(picker)) {
|
||||
throw new Error(getErrorMessage(picker, 'Hour', newValue));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user