Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 0b34519df2ed920ba648c1ecb3ba88c5ed1c4d12 1 parent 87ce700
@carlosantoniodasilva carlosantoniodasilva authored
View
3  CHANGELOG.md
@@ -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`
View
11 lib/simple_form/inputs/boolean_input.rb
@@ -2,14 +2,14 @@ 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
@@ -17,6 +17,13 @@ def label_input
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.
View
2  lib/simple_form/inputs/collection_check_boxes_input.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.