Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4849 from carlosantoniodasilva/checkbox-hidden-form

Replicate :form html5 attribute to hidden field for check_box
  • Loading branch information...
commit 3ccbc619e4e1614c94d19cc9d12bbe7f7826cbdf 2 parents 593fe43 + 3d10955
@josevalim josevalim authored
View
3  actionpack/CHANGELOG.md
@@ -1,5 +1,8 @@
## Rails 4.0.0 (unreleased) ##
+* check_box with `:form` html5 attribute will now replicate the `:form`
+ attribute to the hidden field as well. *Carlos Antonio da Silva*
+
* `label` form helper accepts :for => nil to not generate the attribute. *Carlos Antonio da Silva*
* Add `:format` option to number_to_percentage *Rodrigo Flores*
View
6 actionpack/lib/action_view/helpers/tags/check_box.rb
@@ -25,7 +25,7 @@ def render
add_default_name_and_id(options)
end
- hidden = @unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => @unchecked_value, "disabled" => options["disabled"]) : "".html_safe
+ hidden = hidden_field_for_checkbox(options)
checkbox = tag("input", options)
hidden + checkbox
end
@@ -48,6 +48,10 @@ def checked?(value)
value.to_i != 0
end
end
+
+ def hidden_field_for_checkbox(options)
+ @unchecked_value ? tag("input", options.slice("name", "disabled", "form").merge!("type" => "hidden", "value" => @unchecked_value)) : "".html_safe
+ end
end
end
end
View
13 actionpack/test/template/form_helper_test.rb
@@ -421,6 +421,13 @@ def test_checkbox_disabled_disables_hidden_field
)
end
+ def test_checkbox_form_html5_attribute
+ assert_dom_equal(
+ '<input form="new_form" name="post[secret]" type="hidden" value="0" /><input checked="checked" form="new_form" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
+ check_box("post", "secret", :form => "new_form")
+ )
+ end
+
def test_radio_button
assert_dom_equal('<input checked="checked" id="post_title_hello_world" name="post[title]" type="radio" value="Hello World" />',
radio_button("post", "title", "Hello World")
@@ -2168,8 +2175,8 @@ def test_fields_for_returns_block_result
end
protected
- def protect_against_forgery?
- false
- end
+ def protect_against_forgery?
+ false
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.