diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb index e9d59dcd2..d01174458 100644 --- a/lib/consul_form_builder.rb +++ b/lib/consul_form_builder.rb @@ -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 diff --git a/spec/lib/consul_form_builder_spec.rb b/spec/lib/consul_form_builder_spec.rb index a61e984da..ed896368f 100644 --- a/spec/lib/consul_form_builder_spec.rb +++ b/spec/lib/consul_form_builder_spec.rb @@ -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)