Simplify generating checkboxes in forms

Using the block syntax to generate the label with a <span> tag inside
isn't necessary after upgrading foundation_rails_helpers. Before the
upgrade, we couldn't do so because the <span> tag was escaped.
This commit is contained in:
Javi Martín
2019-10-03 18:53:26 +02:00
parent 5fe56a62f1
commit 8d9cb4d8e3
14 changed files with 98 additions and 152 deletions

View File

@@ -17,6 +17,16 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
end
end
def check_box(attribute, options = {})
if options[:label] != false
label = content_tag(:span, label_text(object, attribute, options[:label]), class: "checkbox")
super(attribute, options.merge(label: label))
else
super
end
end
private
def label_with_hint(attribute, options)
@@ -24,6 +34,14 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
help_text(attribute, options)
end
def label_text(object, attribute, text)
if text.nil? || text == true
default_label_text(object, attribute)
else
text
end
end
def help_text(attribute, options)
if options[:hint]
content_tag :span, options[:hint], class: "help-text", id: help_text_id(attribute, options)