Skip to content

Instantly share code, notes, and snippets.

@tristanm
Created June 6, 2013 23:55
Show Gist options
  • Save tristanm/5726035 to your computer and use it in GitHub Desktop.
Save tristanm/5726035 to your computer and use it in GitHub Desktop.
jQuery buttonset builder for Formtastic
# Custom input to render "flat" checkbox/label pairs for jQuery UI Buttonsets
class CheckBoxButtonsetInput < Formtastic::Inputs::CheckBoxesInput
def to_html
input_wrapping do
choices_wrapping do
legend_html <<
hidden_field_for_all <<
collection.map { |choice|
choice_html(choice)
}.join("\n").html_safe
end
end
end
def choice_html(choice)
(hidden_fields? ? check_box_with_hidden_input(choice) : check_box_without_hidden_input(choice)) <<
template.content_tag(:label, choice_label(choice), label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment