Skip to content

Commit aa9411a

Browse files
refactoring for sonarqube fixes
1 parent f7b8025 commit aa9411a

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/datetime-picker/datetime-picker.component.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ export class DatetimePickerComponent extends AbstractFormFieldComponent implemen
7474
this.dateTimeEntryFormat = this.formatTranslationService.showOnlyDates(this.caseField.dateTimeEntryFormat);
7575
this.configureDatePicker(this.dateTimeEntryFormat);
7676

77-
const existingControl = (this.parent || this.formGroup)?.controls?.[this.caseField.id];
78-
7977
// for when navigating back to an existing form
8078
this.dateControl = (this.caseField.isMandatory ?
8179
this.registerControl(new FormControl(this.caseField.value || '', [Validators.required]))
@@ -250,21 +248,19 @@ export class DatetimePickerComponent extends AbstractFormFieldComponent implemen
250248
this.dateControl.setValue(keepErrorText);
251249
this.inputElement.nativeElement.value = keepErrorText;
252250
}
253-
} else {
251+
} else if (this.localDisplayControl.value) {
254252
// input is empty - check if we need to sync from control values
255-
if (this.localDisplayControl.value) {
256-
// control has a value but input doesn't - this happens when navigating back
257-
// manually sync the control value to the input element
258-
const controlValue = this.localDisplayControl.value;
259-
const parsedMoment = moment(controlValue, this.momentFormat);
260-
if (parsedMoment.isValid()) {
261-
const formattedValue = parsedMoment.format(this.dateTimeEntryFormat);
262-
this.inputElement.nativeElement.value = formattedValue;
263-
}
264-
} else if (!this.dateControl.value) {
265-
this.localDisplayControl.setValue('');
266-
this.dateControl.setValue('');
253+
// control has a value but input doesn't - this happens when navigating back
254+
// manually sync the control value to the input element
255+
const controlValue = this.localDisplayControl.value;
256+
const parsedMoment = moment(controlValue, this.momentFormat);
257+
if (parsedMoment.isValid()) {
258+
const formattedValue = parsedMoment.format(this.dateTimeEntryFormat);
259+
this.inputElement.nativeElement.value = formattedValue;
267260
}
261+
} else if (!this.dateControl.value) {
262+
this.localDisplayControl.setValue('');
263+
this.dateControl.setValue('');
268264
}
269265
}
270266
}

0 commit comments

Comments
 (0)