Created
October 3, 2011 13:25
-
-
Save fabioyamate/1259098 to your computer and use it in GitHub Desktop.
Simple Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d6baaf8ed0f0cddbd311210042f3b91fa800b737 Mon Sep 17 00:00:00 2001 | |
From: Fabio Yamate <fabio.yamate@plataformatec.com.br> | |
Date: Mon, 3 Oct 2011 01:18:07 -0300 | |
Subject: [PATCH] Add checkboxes collection bootstrap. | |
--- | |
lib/simple_form/action_view_extensions/builder.rb | 7 ++++--- | |
lib/simple_form/components/labels.rb | 4 ++-- | |
lib/simple_form/inputs/boolean_input.rb | 8 ++++++-- | |
3 files changed, 12 insertions(+), 7 deletions(-) | |
diff --git a/lib/simple_form/action_view_extensions/builder.rb b/lib/simple_form/action_view_extensions/builder.rb | |
index 8706be0..7d8ee77 100644 | |
--- a/lib/simple_form/action_view_extensions/builder.rb | |
+++ b/lib/simple_form/action_view_extensions/builder.rb | |
@@ -83,8 +83,9 @@ module SimpleForm | |
) do |value, text, default_html_options| | |
default_html_options[:multiple] = true | |
- check_box(attribute, default_html_options, value, '') + | |
- label(sanitize_attribute_name(attribute, value), text, :class => "collection_check_boxes") | |
+ label(sanitize_attribute_name(attribute, value), text, :class => "collection_check_boxes") do | |
+ check_box(attribute, default_html_options, value, '') + " "+ template.content_tag(:span, text) | |
+ end | |
end | |
end | |
@@ -147,7 +148,7 @@ module SimpleForm | |
item_wrapper_tag ? @template.content_tag(item_wrapper_tag, rendered_item) : rendered_item | |
end.join.html_safe | |
- collection_wrapper_tag ? @template.content_tag(collection_wrapper_tag, rendered_collection) : rendered_collection | |
+ collection_wrapper_tag ? @template.content_tag(collection_wrapper_tag, rendered_collection, :class => "inputs-list") : rendered_collection | |
end | |
def value_for_collection(item, value) #:nodoc: | |
diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb | |
index e49ce49..2f38439 100644 | |
--- a/lib/simple_form/components/labels.rb | |
+++ b/lib/simple_form/components/labels.rb | |
@@ -21,8 +21,8 @@ module SimpleForm | |
end | |
end | |
- def label | |
- @builder.label(label_target, label_text, label_html_options) | |
+ def label(&block) | |
+ @builder.label(label_target, label_text, label_html_options, &block) | |
end | |
def label_text | |
diff --git a/lib/simple_form/inputs/boolean_input.rb b/lib/simple_form/inputs/boolean_input.rb | |
index 9255bfd..675cd00 100644 | |
--- a/lib/simple_form/inputs/boolean_input.rb | |
+++ b/lib/simple_form/inputs/boolean_input.rb | |
@@ -6,7 +6,11 @@ module SimpleForm | |
end | |
def label_input | |
- input + (options[:label] == false ? "" : label) | |
+ if options[:label] == false | |
+ input | |
+ else | |
+ label { input + @builder.template.content_tag(:span, label_text) } | |
+ end | |
end | |
private | |
@@ -19,4 +23,4 @@ module SimpleForm | |
end | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end | |
-- | |
1.7.7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment