Permalink
Browse files

Creates correct checkbox markup for Bootstrap 3.

  • Loading branch information...
1 parent 0538a91 commit 2c94216e0e07f15bf75fe91b851b3316e9d7a48d @mjbellantoni committed Nov 25, 2013
@@ -5,23 +5,33 @@ class BooleanInput < Formtastic::Inputs::BooleanInput
include Base
def to_html
- form_group_wrapping do
- (options[:label_outside] ? label_html : "".html_safe) <<
- hidden_field_html <<
+ checkbox_wrapping do
+ "".html_safe <<
[label_with_nested_checkbox, hint_html].join("\n").html_safe
end
end
def label_with_nested_checkbox
builder.label(
method,
- options[:label_outside] ? check_box_html : label_text_with_embedded_checkbox,
- label_html_options.tap do |options|
- options[:class] << "checkbox"
- end
+ label_text_with_embedded_checkbox,
+ label_html_options
)
end
+ def checkbox_wrapping(&block)
+ template.content_tag(:div,
+ template.capture(&block).html_safe,
+ wrapper_html_options
+ )
+ end
+
+ def wrapper_html_options
+ super.tap do |options|
+ options[:class] = (options[:class].split - ["form-group"] + ["checkbox"]).join(" ")
+ end
+ end
+
end
end
end
@@ -10,26 +10,29 @@ class CheckBoxesInput < Formtastic::Inputs::CheckBoxesInput
def to_html
form_group_wrapping do
label_html <<
- hidden_field_for_all <<
+ hidden_field_for_all << # Might need to remove this guy.
collection.map { |choice|
choice_html(choice)
}.join("\n").html_safe
end
end
- def choice_wrapping_html_options(choice)
- super(choice).tap do |options|
- options[:class] = ((options[:class].split) << "checkbox").join(" ")
+ def choice_html(choice)
+ checkbox_wrapping do
+ template.content_tag(:label,
+ hidden_fields? ?
+ check_box_with_hidden_input(choice) :
+ check_box_without_hidden_input(choice) <<
+ choice_label(choice),
+ label_html_options.merge(choice_label_html_options(choice))
+ )
end
end
- def choice_html(choice)
- template.content_tag(:label,
- hidden_fields? ?
- check_box_with_hidden_input(choice) :
- check_box_without_hidden_input(choice) <<
- choice_label(choice),
- label_html_options.merge(choice_label_html_options(choice))
+ def checkbox_wrapping(&block)
+ template.content_tag(:div,
+ template.capture(&block).html_safe,
+ :class => "checkbox"
)
end

0 comments on commit 2c94216

Please sign in to comment.