Skip to content

Commit

Permalink
#368 Timepicker component doesn't handle errors properly (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
fateeand authored Apr 10, 2024
1 parent 5c1d07a commit 8c9bbd7
Showing 1 changed file with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class CpsTimepickerComponent
// eslint-disable-next-line @typescript-eslint/no-empty-function
setDisabledState(disabled: boolean) {}

writeValue(value: CpsTime) {
writeValue(value: CpsTime | undefined) {
this.value = value;
}

Expand All @@ -236,7 +236,8 @@ export class CpsTimepickerComponent
}

updateHours(hours: string) {
const userInput = this.hoursField?.inputText || hours || '';
hours = hours || '';
const userInput = this.hoursField?.inputText || hours;
if (userInput) {
this._initValue();
const h = parseInt(userInput, 10);
Expand All @@ -250,7 +251,7 @@ export class CpsTimepickerComponent
if (this.value?.hours !== hours) {
if (this.value) this.value.hours = hours;
}
this._tryUpdateValue();
this._updateValue(this.value);
}

updateMinutes(minutes: string) {
Expand All @@ -259,7 +260,7 @@ export class CpsTimepickerComponent
if (this.value?.minutes !== minutes) {
if (this.value) this.value.minutes = minutes;
}
this._tryUpdateValue();
this._updateValue(this.value);
}

updateSeconds(seconds: string) {
Expand All @@ -268,15 +269,15 @@ export class CpsTimepickerComponent
if (this.value?.seconds !== seconds) {
if (this.value) this.value.seconds = seconds;
}
this._tryUpdateValue();
this._updateValue(this.value);
}

updateDayPeriod(dayPeriod: 'AM' | 'PM') {
if (dayPeriod) this._initValue();
if (this.value?.dayPeriod !== dayPeriod) {
if (this.value) this.value.dayPeriod = dayPeriod;
}
this._tryUpdateValue();
this._updateValue(this.value);
}

numberOnly(event: any): boolean {
Expand Down Expand Up @@ -373,22 +374,12 @@ export class CpsTimepickerComponent
});
}

private _updateValue(value: CpsTime) {
private _updateValue(value: CpsTime | undefined) {
this.writeValue(value);
this.onChange(value);
this.valueChanged.emit(value);
}

private _tryUpdateValue() {
if (
this.value?.hours &&
this.value?.minutes &&
(!this.withSeconds || (this.withSeconds && this.value?.seconds)) &&
(this.use24HourTime || (!this.use24HourTime && this.value?.dayPeriod))
)
this._updateValue(this.value);
}

private _getRange(startFrom: number, until: number) {
return Array.from(
{ length: until + 1 - startFrom },
Expand Down

0 comments on commit 8c9bbd7

Please sign in to comment.