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

Reuse user value if field is in error state

Christophe Bliardb35d9d155ac9
diff --git a/app/forms/work_packages/progress_form.rb b/app/forms/work_packages/progress_form.rb
index c0d46859599..37e448fb154 100644
--- a/app/forms/work_packages/progress_form.rb
+++ b/app/forms/work_packages/progress_form.rb
@@ -102,7 +102,7 @@ class WorkPackages::ProgressForm < ApplicationForm
placeholder: nil)
text_field_options = {
name:,
- value: format_to_smallest_fractional_part(@work_package.send(name)),
+ value: field_value(name),
label:,
disabled:,
placeholder:
@@ -119,7 +119,7 @@ class WorkPackages::ProgressForm < ApplicationForm
placeholder: true)
text_field_options = {
name:,
- value: format_to_smallest_fractional_part(@work_package.send(name)),
+ value: field_value(name),
label:,
readonly: true,
disabled:,
@@ -131,6 +131,15 @@ class WorkPackages::ProgressForm < ApplicationForm
group.text_field(**text_field_options)
end
+ def field_value(name)
+ errors = @work_package.errors.where(name)
+ if user_value = errors.map { |error| error.options[:value] }.find { !_1.nil? }
+ user_value
+ else
+ format_to_smallest_fractional_part(@work_package.public_send(name))
+ end
+ end
+
def format_to_smallest_fractional_part(number)
return number if number.nil?