Merge pull request #4791 from consul/label_with_interpolation

Fix crash on attributes with interpolation arguments
This commit is contained in:
Javi Martín
2022-03-28 19:09:09 +02:00
committed by GitHub
2 changed files with 22 additions and 3 deletions

View File

@@ -76,14 +76,14 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
end
def help_text(attribute, options)
if options[:hint]
if options[:hint].present?
tag.span options[:hint], class: "help-text", id: help_text_id(attribute, options)
end
end
def help_text_id(attribute, options)
if options[:hint]
"#{custom_label(attribute, nil, nil).match(/for="([^"]+)"/)[1]}-help-text"
if options[:hint].present?
"#{custom_label(attribute, "Example", nil).match(/for="([^"]+)"/)[1]}-help-text"
end
end
end

View File

@@ -28,11 +28,30 @@ describe ConsulFormBuilder do
expect(page).to have_css "input[aria-describedby='dummy_title-help-text']"
end
it "does not generate empty hints" do
render builder.text_field(:title, hint: "")
expect(page).not_to have_css ".help-text"
expect(page).not_to have_css "input[aria-describedby]"
end
it "does not generate a hint attribute" do
render builder.text_field(:title)
expect(page).not_to have_css "input[hint]"
end
describe "attributes requiring interpolation parameters" do
before { I18n.backend.store_translations(:en, { attributes: { title: "Title %{info}" }}) }
after { I18n.backend.reload! }
it "generates a hint" do
render builder.text_field(:title, label: "Title whatever", hint: "Make it quick")
expect(page).to have_css ".help-text", text: "Make it quick"
expect(page).to have_css "input[aria-describedby='dummy_title-help-text']"
end
end
end
describe "#select" do