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:
@@ -197,6 +197,13 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
|
|||||||
TKUnit.assertEqual(actualValue, expectedValue);
|
TKUnit.assertEqual(actualValue, expectedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public testHourZeroFromLocalToNative() {
|
||||||
|
let expectedValue = 0;
|
||||||
|
this.testView.hour = expectedValue;
|
||||||
|
let actualValue = timePickerTestsNative.getNativeHour(this.testView);
|
||||||
|
TKUnit.assertEqual(actualValue, expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
public testMinuteFromLocalToNative() {
|
public testMinuteFromLocalToNative() {
|
||||||
let expectedValue = 59;
|
let expectedValue = 59;
|
||||||
this.testView.minute = expectedValue;
|
this.testView.minute = expectedValue;
|
||||||
@@ -204,6 +211,13 @@ export class TimePickerTest extends testModule.UITest<timePickerModule.TimePicke
|
|||||||
TKUnit.assertEqual(actualValue, expectedValue);
|
TKUnit.assertEqual(actualValue, expectedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public testMinuteZeroFromLocalToNative() {
|
||||||
|
let expectedValue = 0;
|
||||||
|
this.testView.minute = expectedValue;
|
||||||
|
let actualValue = timePickerTestsNative.getNativeMinute(this.testView);
|
||||||
|
TKUnit.assertEqual(actualValue, expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
public testHourFromNativeToLocal() {
|
public testHourFromNativeToLocal() {
|
||||||
let expectedValue = 14;
|
let expectedValue = 14;
|
||||||
timePickerTestsNative.setNativeHour(this.testView, expectedValue);
|
timePickerTestsNative.setNativeHour(this.testView, expectedValue);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export function navigatingTo(args: EventData) {
|
|||||||
export class SampleData extends Observable {
|
export class SampleData extends Observable {
|
||||||
minDate = new Date();
|
minDate = new Date();
|
||||||
maxDate = new Date(2030, 7, 1);
|
maxDate = new Date(2030, 7, 1);
|
||||||
|
hour = 8;
|
||||||
|
minute = 0;
|
||||||
displayDate = {
|
displayDate = {
|
||||||
day: new Date().getDate(),
|
day: new Date().getDate(),
|
||||||
month: new Date().getMonth(),
|
month: new Date().getMonth(),
|
||||||
|
|||||||
@@ -16,5 +16,9 @@ year="{{displayDate?.year}}"
|
|||||||
<Switch checked="true" col="0" checkedChange="{{checkedChange}}" />
|
<Switch checked="true" col="0" checkedChange="{{checkedChange}}" />
|
||||||
<Label text="Show Time" col="1" class="m-l-10" />
|
<Label text="Show Time" col="1" class="m-l-10" />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
<GridLayout rows="auto,auto" columns="">
|
||||||
|
<Label text="Time Picker standalone:" row="0" col="0" class="m-t-10" />
|
||||||
|
<TimePicker row="1" hour="{{hour}}" minute="{{minute}}"></TimePicker>
|
||||||
|
</GridLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -165,8 +165,11 @@ minuteIntervalProperty.register(TimePickerBase);
|
|||||||
|
|
||||||
export const minuteProperty = new Property<TimePickerBase, number>({
|
export const minuteProperty = new Property<TimePickerBase, number>({
|
||||||
name: 'minute',
|
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) => {
|
valueChanged: (picker, oldValue, newValue) => {
|
||||||
|
newValue = newValue || 0;
|
||||||
if (!isMinuteValid(newValue) || !isValidTime(picker)) {
|
if (!isMinuteValid(newValue) || !isValidTime(picker)) {
|
||||||
throw new Error(getErrorMessage(picker, 'minute', newValue));
|
throw new Error(getErrorMessage(picker, 'minute', newValue));
|
||||||
}
|
}
|
||||||
@@ -179,8 +182,11 @@ minuteProperty.register(TimePickerBase);
|
|||||||
|
|
||||||
export const hourProperty = new Property<TimePickerBase, number>({
|
export const hourProperty = new Property<TimePickerBase, number>({
|
||||||
name: 'hour',
|
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) => {
|
valueChanged: (picker, oldValue, newValue) => {
|
||||||
|
newValue = newValue || 0;
|
||||||
if (!isHourValid(newValue) || !isValidTime(picker)) {
|
if (!isHourValid(newValue) || !isValidTime(picker)) {
|
||||||
throw new Error(getErrorMessage(picker, 'Hour', newValue));
|
throw new Error(getErrorMessage(picker, 'Hour', newValue));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user