From 5e1702eef0755591356ac42871b2a9dd2b04bb4a Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Thu, 19 Feb 2026 16:12:15 +0100 Subject: [PATCH] use complete label for comment field if there are multiple custom fields rendered --- app/forms/custom_fields/comment_field.rb | 5 +++-- app/forms/custom_fields/custom_field_rendering.rb | 13 +++++++++++-- spec/forms/custom_fields/comment_field_spec.rb | 8 ++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/forms/custom_fields/comment_field.rb b/app/forms/custom_fields/comment_field.rb index 2fe3d107a0a..035498df76e 100644 --- a/app/forms/custom_fields/comment_field.rb +++ b/app/forms/custom_fields/comment_field.rb @@ -34,17 +34,18 @@ module CustomFields comment_form.text_area(**attributes) end - def initialize(custom_field:, object:) + def initialize(custom_field:, object:, complete_label: false) super() @custom_field = custom_field @object = object + @complete_label = complete_label end def attributes { name: @custom_field.id.to_s, - label: I18n.t("attributes.comment"), + label: @complete_label ? I18n.t(:label_custom_comment, name: @custom_field.name) : I18n.t("attributes.comment"), value: @custom_field.comment_for(@object)&.text, rows: 5 } diff --git a/app/forms/custom_fields/custom_field_rendering.rb b/app/forms/custom_fields/custom_field_rendering.rb index d68e062aed4..8e5063e2991 100644 --- a/app/forms/custom_fields/custom_field_rendering.rb +++ b/app/forms/custom_fields/custom_field_rendering.rb @@ -57,7 +57,7 @@ module CustomFields::CustomFieldRendering end if custom_field.has_comment? form.fields_for(:custom_comments) do |builder| - CustomFields::CommentField.new(builder, custom_field: custom_field, object: model) + custom_comment_input(builder, custom_field) end end end @@ -82,9 +82,18 @@ module CustomFields::CustomFieldRendering end end + def custom_comment_input(builder, custom_field) + CustomFields::CommentField.new( + builder, + custom_field:, + object: model, + complete_label: custom_fields.length > 1 + ) + end + def form_arguments(custom_field) { - custom_field: custom_field, + custom_field:, object: model }.merge(additional_custom_field_input_arguments) end diff --git a/spec/forms/custom_fields/comment_field_spec.rb b/spec/forms/custom_fields/comment_field_spec.rb index ce4752d2adf..f78efa36b4d 100644 --- a/spec/forms/custom_fields/comment_field_spec.rb +++ b/spec/forms/custom_fields/comment_field_spec.rb @@ -37,6 +37,14 @@ RSpec.describe CustomFields::CommentField, type: :forms do it_behaves_like "rendering label", "Comment" + context "when showing complete label" do + def build_form(builder) + described_class.new(builder, custom_field:, object: model, complete_label: true) + end + + it_behaves_like "rendering label", "Project custom field comment" + end + context "without a value" do it "renders field" do expect(rendered_form).to have_field "Comment", type: :textarea, with: ""