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 datepicker UI integration to work with highlighted fields and auto focusing missing date fields.

Dombi Attilabf864edeabcc
diff --git a/app/forms/projects/life_cycles/form.rb b/app/forms/projects/life_cycles/form.rb
index d4026576f59..7faa6095abe 100644
--- a/app/forms/projects/life_cycles/form.rb
+++ b/app/forms/projects/life_cycles/form.rb
@@ -67,7 +67,8 @@ module Projects::LifeCycles
caption:,
value:,
data: data.merge("overview--project-life-cycles-form-target": "startDate assignable"),
- show_clear_button: value.present? && !disabled
+ show_clear_button: value.present? && !disabled,
+ clear_button_id: "start_date_clear_button"
}
form.text_field **datepicker_attributes, **input_attributes
end
@@ -81,7 +82,8 @@ module Projects::LifeCycles
autofocus: autofocus?(:finish_date),
value:,
data: data.merge("overview--project-life-cycles-form-target": "finishDate assignable"),
- show_clear_button: value.present?
+ show_clear_button: value.present?,
+ clear_button_id: "finish_date_clear_button"
}
form.text_field **datepicker_attributes, **input_attributes
end
diff --git a/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts
index 6ee0d599663..765fd62cf63 100644
--- a/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts
@@ -81,7 +81,7 @@ export default class ProjectLifeCyclesFormController extends FormPreviewControll
private updateFlatpickrCalendar() {
const dates:Date[] = _.compact(this.dateInputFields.map((field) => this.toDate(field.value)));
const ignoreNonWorkingDays = false;
- const mode = this.mode;
+ const mode = 'range';
document.dispatchEvent(
new CustomEvent('date-picker:flatpickr-set-values', {
@@ -94,31 +94,19 @@ export default class ProjectLifeCyclesFormController extends FormPreviewControll
);
}
- private get mode():'single'|'range' {
- return 'range';
- }
-
- highlightField(field:HTMLInputElement) {
- this.clearHighLight();
- field.classList.add('op-datepicker-modal--date-field_current');
- this.updateFlatpickrCalendar();
- window.setTimeout(() => {
- // For mobile, we have to make sure that the active field is scrolled into view after the keyboard is opened
- field.scrollIntoView(true);
- }, 300);
- }
-
handleFlatpickrDatesChanged(event:CustomEvent<{ dates:Date[] }>) {
const dates = event.detail.dates;
if (dates.length === 1) {
if ((this.highlightedField === this.finishDateTarget) || this.startDateTarget.disabled) {
this.finishDateTarget.value = this.dateToIso(dates[0]);
- if (this.startDateTarget.disabled) {
- this.clearHighLight();
+ if (!this.startDateTarget.value) {
+ this.highlightField(this.startDateTarget);
}
} else {
this.startDateTarget.value = this.dateToIso(dates[0]);
+ this.finishDateTarget.value = '';
+ this.highlightField(this.finishDateTarget);
}
} else {
this.dateInputFields
@@ -129,6 +117,7 @@ export default class ProjectLifeCyclesFormController extends FormPreviewControll
});
this.clearHighLight();
}
+
this.updateFlatpickrCalendar();
this.previewForm();
}
@@ -156,6 +145,21 @@ export default class ProjectLifeCyclesFormController extends FormPreviewControll
return field;
}
+ private highlightField(field:HTMLInputElement) {
+ this.clearHighLight();
+
+ if (field.disabled) {
+ return;
+ }
+
+ field.classList.add('op-datepicker-modal--date-field_current');
+ this.updateFlatpickrCalendar();
+ window.setTimeout(() => {
+ // For mobile, we have to make sure that the active field is scrolled into view after the keyboard is opened
+ field.scrollIntoView(true);
+ }, 300);
+ }
+
private clearHighLight() {
this.dateInputFields
.forEach((el) => el.classList.remove('op-datepicker-modal--date-field_current'));