mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
use complete label for comment field if there are multiple custom fields rendered
This commit is contained in:
@@ -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: ""
|
||||
|
||||
Reference in New Issue
Block a user