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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user