Do not generate an empty hint element when there's an empty hint

This commit is contained in:
taitus
2022-03-17 10:35:52 +01:00
committed by Javi Martín
parent ab0572f32a
commit d719b2291e
2 changed files with 9 additions and 2 deletions

View File

@@ -76,13 +76,13 @@ 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]
if options[:hint].present?
"#{custom_label(attribute, nil, nil).match(/for="([^"]+)"/)[1]}-help-text"
end
end

View File

@@ -28,6 +28,13 @@ 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)