use complete label for comment field if there are multiple custom fields rendered

This commit is contained in:
Ivan Kuchin
2026-02-19 16:12:15 +01:00
parent 7fd844b57f
commit 5e1702eef0
3 changed files with 22 additions and 4 deletions
+3 -2
View File
@@ -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
}
@@ -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
@@ -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: ""