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

Switch the focused date field if one of the values is empty

Henriette Dargec1d01f1dfb87
diff --git a/app/forms/work_packages/date_picker/date_form.rb b/app/forms/work_packages/date_picker/date_form.rb
index cce05044646..e69e8846b97 100644
--- a/app/forms/work_packages/date_picker/date_form.rb
+++ b/app/forms/work_packages/date_picker/date_form.rb
@@ -61,7 +61,7 @@ module WorkPackages
@work_package = work_package
@schedule_manually = schedule_manually
@is_milestone = is_milestone
- @focused_field = focused_field
+ @focused_field = update_focused_field
@touched_field_map = touched_field_map
@disabled = disabled
end
@@ -106,7 +106,7 @@ module WorkPackages
validation_message: validation_message(name)
)
- if name == :duration
+ if duration_field?(name)
text_field_options = text_field_options.merge(
trailing_visual: { text: { text: I18n.t("datetime.units.day.other") } }
)
@@ -145,6 +145,22 @@ module WorkPackages
name == :duration
end
+ def update_focused_field
+ return @focused_field if @focused_field == :duration
+
+ if @focused_field.nil?
+ @focused_field = :start_date
+ end
+
+ opposite_field = @focused_field == :start_date ? :due_date : :start_date
+
+ if field_value(@focused_field).present? && field_value(opposite_field).nil?
+ opposite_field
+ else
+ @focused_field
+ end
+ end
+
def disabled?(name)
if name == :duration
if !@schedule_manually && @work_package.children.any?