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

Prevent re-initialising the datepicker date when the non working days switch is toggled on the single datepicker

Dombi Attila789400122dcb
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 22458138cd1..0206a00cf0b 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
@@ -125,7 +125,8 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
@Input() showIgnoreNonWorkingDays = false;
- @Input() ignoreNonWorkingDays = false;
+ // When the "Working days only" switch is shown, it should be on, otherwise is off.
+ @Input() ignoreNonWorkingDays = !this.showIgnoreNonWorkingDays;
@ViewChild('flatpickrTarget') flatpickrTarget:ElementRef;
@@ -161,6 +162,9 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
ngOnInit() {
this.applyLabel = this.applyLabel || this.text.apply;
+ // The showIgnoreNonWorkingDays can come from the populateInputsFromDataset,
+ // hence we need to set the ignoreNonWorkingDays default here as well.
+ this.ignoreNonWorkingDays = !this.showIgnoreNonWorkingDays;
}
ngAfterContentInit() {
@@ -193,7 +197,7 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
}
changeNonWorkingDays():void {
- this.initializeDatepickerAfterOpen();
+ this.initializeDatepicker(false);
this.cdRef.detectChanges();
}
@@ -228,12 +232,13 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
});
}
- private initializeDatepicker() {
+ private initializeDatepicker(setInitialDate = true) {
this.datePickerInstance?.destroy();
- // Initialize the working values.
- const initialDate = parseDate(this.value || new Date()) as Date;
- this.writeWorkingValue(this.timezoneService.formattedISODate(initialDate));
+ if (setInitialDate) {
+ const initialDate = parseDate(this.value || new Date()) as Date;
+ this.writeWorkingValue(this.timezoneService.formattedISODate(initialDate));
+ }
this.datePickerInstance = new DatePicker(
this.injector,
diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb
index 9c680e32384..ad43f05ebdd 100644
--- a/lib/tabular_form_builder.rb
+++ b/lib/tabular_form_builder.rb
@@ -106,6 +106,10 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
inputs['remote-field-key'] = options.dig(:data, :'remote-field-key')
end
+ if !options[:show_ignore_non_working_days].nil?
+ inputs['show-ignore-non-working-days'] = options[:show_ignore_non_working_days]
+ end
+
label = label_for_field(field, label_options)
input = angular_component_tag('op-single-date-picker',
class: options[:class],