mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Improve previous patch a bit [#3645 state:resolved]
This commit is contained in:
parent
6e69b42b21
commit
d18a2742e0
3 changed files with 11 additions and 9 deletions
|
@ -576,12 +576,12 @@ module ActionView
|
|||
# label(:post, :terms) do
|
||||
# 'Accept <a href="/terms">Terms</a>.'
|
||||
# end
|
||||
def label(object_name, method, content_or_options_with_block = nil, options = nil, &block)
|
||||
def label(object_name, method, content_or_options = nil, options = nil, &block)
|
||||
if block_given?
|
||||
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
|
||||
options = content_or_options if content_or_options.is_a?(Hash)
|
||||
text = nil
|
||||
else
|
||||
text = content_or_options_with_block
|
||||
text = content_or_options
|
||||
end
|
||||
|
||||
options ||= {}
|
||||
|
|
|
@ -156,15 +156,12 @@ module ActionView
|
|||
#
|
||||
# label_tag 'name', nil, :class => 'small_label'
|
||||
# # => <label for="name" class="small_label">Name</label>
|
||||
def label_tag(name = nil, content_or_options_with_block = nil, options = nil, &block)
|
||||
if block_given?
|
||||
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
|
||||
end
|
||||
|
||||
def label_tag(name = nil, content_or_options = nil, options = nil, &block)
|
||||
options = content_or_options if block_given? && content_or_options.is_a?(Hash)
|
||||
options ||= {}
|
||||
options.stringify_keys!
|
||||
options["for"] = sanitize_to_id(name) unless name.blank? || options.has_key?("for")
|
||||
content_tag :label, content_or_options_with_block || name.to_s.humanize, options, &block
|
||||
content_tag :label, content_or_options || name.to_s.humanize, options, &block
|
||||
end
|
||||
|
||||
# Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or
|
||||
|
|
|
@ -297,6 +297,11 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
assert_dom_equal('<label for="clock">Grandfather</label>', output)
|
||||
end
|
||||
|
||||
def test_label_tag_with_block_and_argument_and_options
|
||||
output = label_tag("clock", :id => "label_clock") { "Grandfather" }
|
||||
assert_dom_equal('<label for="clock" id="label_clock">Grandfather</label>', output)
|
||||
end
|
||||
|
||||
def test_boolean_options
|
||||
assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
|
||||
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
|
||||
|
|
Loading…
Reference in a new issue