提交 37b4ba21 编写于 作者: J José Valim

Merge pull request #4337 from tadast/master-checkbox_patch

check_box helper with :disabled => true generates disabled hidden field. fixes #1953 (master)
## Rails 3.2.0 (unreleased) ## ## Rails 3.2.0 (unreleased) ##
* check_box helper with :disabled => true will generate a disabled hidden field to conform with the HTML convention where disabled fields are not submitted with the form.
This is a behavior change, previously the hidden tag had a value of the disabled checkbox.
*Tadas Tamosauskas*
* Add font_path helper method *Santiago Pastorino* * Add font_path helper method *Santiago Pastorino*
* Depends on rack ~> 1.4.0 *Santiago Pastorino* * Depends on rack ~> 1.4.0 *Santiago Pastorino*
......
...@@ -1091,7 +1091,7 @@ def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0") ...@@ -1091,7 +1091,7 @@ def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
else else
add_default_name_and_id(options) add_default_name_and_id(options)
end end
hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value) hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"])
checkbox = tag("input", options) checkbox = tag("input", options)
hidden + checkbox hidden + checkbox
end end
......
...@@ -386,11 +386,10 @@ def test_check_box_with_multiple_behavior ...@@ -386,11 +386,10 @@ def test_check_box_with_multiple_behavior
) )
end end
def test_checkbox_disabled_disables_hidden_field
def test_checkbox_disabled_still_submits_checked_value
assert_dom_equal( assert_dom_equal(
'<input name="post[secret]" type="hidden" value="1" /><input checked="checked" disabled="disabled" id="post_secret" name="post[secret]" type="checkbox" value="1" />', '<input name="post[secret]" type="hidden" value="0" disabled="disabled"/><input checked="checked" disabled="disabled" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
check_box("post", "secret", { :disabled => :true }) check_box("post", "secret", { :disabled => true })
) )
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册