Permalink
Browse files

Do not generate hidden check box field when using nested boolean style

It is considered invalid markup in HTML5. This will only work in
Rails > 3.2.1 (not released at this time). If you really care that much
about this, please use Rails 3-2-stable branch for now, that contains a
backported fix from master.

Backport commit: rails/rails@2e5ec3b
More info in #215
  • Loading branch information...
1 parent 87ce700 commit 0b34519df2ed920ba648c1ecb3ba88c5ed1c4d12 @carlosantoniodasilva carlosantoniodasilva committed Jan 27, 2012
View
@@ -27,6 +27,9 @@
* Add possibility to give a block to `collection_radio` and `collection_check_boxes`,
to generate custom label and input structure. It is used internally with the :nested
option for `:boolean_style`, and is useful to allow some more customization if required.
+ * Do not generate hidden check box field when using nested boolean style, as it is considered
+ invalid markup in HTML5. This will only work in Rails > 3.2.1 (not released at this time).
+ More info in [#215](https://github.com/plataformatec/simple_form/issues/215)
### deprecation
* Deprecate the `translate` configuration in favor of `translate_labels`
@@ -2,21 +2,28 @@ module SimpleForm
module Inputs
class BooleanInput < Base
def input
- @builder.check_box(attribute_name, input_html_options)
+ build_check_box
end
def label_input
if options[:label] == false
input
elsif nested_boolean_style?
- @builder.label(label_target, label_html_options) { input + label_text }
+ @builder.label(label_target, label_html_options) { build_check_box(nil) + label_text }
else
input + label
end
end
private
+ # Build a checkbox tag using default unchecked value. This allows us to
+ # reuse the method for nested boolean style, but with nil unchecked value,
+ # which won't generate the hidden checkbox (only in Rails > 3.2.1).
+ def build_check_box(unchecked_value='0')
+ @builder.check_box(attribute_name, input_html_options, '1', unchecked_value)
+ end
+
# Booleans are not required by default because in most of the cases
# it makes no sense marking them as required. The only exception is
# Terms of Use usually presented at most sites sign up screen.
@@ -10,7 +10,7 @@ def has_required?
end
def nested_boolean_style_item_tag(value, html_options)
- @builder.check_box(attribute_name, html_options, value)
+ @builder.check_box(attribute_name, html_options, value, nil)
end
end
end

0 comments on commit 0b34519

Please sign in to comment.