Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Make the datepicker to receive changes from the trigger input element

Dombi Attilada85a1df9c14
diff --git a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html
index 22c32b578a3..1a1fa38439b 100644
--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html
+++ b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html
@@ -13,11 +13,12 @@
[attr.data-value]="value"
[id]="id"
(click)="onInputClick($event)"
- [value]="value"
+ [(ngModel)]="value"
+ (ngModelChange)="changeValueFromInputDebounced($event)"
(focus)="opened = true"
/>
</ng-template>
-
+
<ng-container slot="body">
<form
class="spot-container op-datepicker-modal"
diff --git a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts
index d2330cfdc6c..6a769eafedd 100644
--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts
+++ b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts
@@ -152,7 +152,7 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, AfterC
}
ngAfterContentInit() {
- const trigger = this.elementRef.nativeElement.querySelector("[slot='trigger']");
+ const trigger = (this.elementRef.nativeElement as HTMLElement).querySelector("[slot='trigger']");
this.useDefaultTrigger = trigger === null;
}
@@ -180,6 +180,25 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, AfterC
this.cdRef.detectChanges();
}
+ changeValueFromInputDebounced = debounce(this.changeValueFromInput.bind(this), 16);
+
+ changeValueFromInput(value:string) {
+ this.valueChange.emit(value);
+ this.onChange(value);
+ this.writeValue(value);
+
+ const date = parseDate(value || '');
+
+ if (date !== '') {
+ const dateString = this.timezoneService.formattedISODate(date);
+ this.writeWorkingValue(dateString);
+ this.enforceManualChangesToDatepicker(date);
+ this.onTouched(dateString);
+ }
+
+ this.cdRef.detectChanges();
+ }
+
private enforceManualChangesToDatepicker(enforceDate?:Date) {
const date = parseDate(this.workingDate || '');
setDates(date, this.datePickerInstance, enforceDate);
@@ -229,7 +248,7 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, AfterC
);
},
},
- this.flatpickrTarget.nativeElement,
+ this.flatpickrTarget.nativeElement as HTMLElement,
);
}
diff --git a/spec/support/form_fields/input_form_field.rb b/spec/support/form_fields/input_form_field.rb
index 11673aa493c..de2d25a4974 100644
--- a/spec/support/form_fields/input_form_field.rb
+++ b/spec/support/form_fields/input_form_field.rb
@@ -15,7 +15,7 @@ module FormFields
# Set or select the given value.
# For fields of type select, will check for an option with that value.
def set_value(content)
- scroll_to_element(input_element)
+ scroll_to_and_click(input_element)
# A normal fill_in would cause the focus loss on the input for empty strings.
# Thus the form would be submitted.