mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use include_blank value as option label
Update select_tag to reflect documentation and behave the same as form builder select. If the value of include_blank is not boolean true, use that value as the option label.
This commit is contained in:
parent
4af5899e25
commit
d611036c77
2 changed files with 14 additions and 2 deletions
|
@ -133,8 +133,14 @@ module ActionView
|
||||||
option_tags ||= ""
|
option_tags ||= ""
|
||||||
html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
|
html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
|
||||||
|
|
||||||
if options.delete(:include_blank)
|
|
||||||
option_tags = content_tag(:option, '', :value => '').safe_concat(option_tags)
|
if options.include?(:include_blank)
|
||||||
|
include_blank = options.delete(:include_blank)
|
||||||
|
if include_blank == true
|
||||||
|
include_blank = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
option_tags = content_tag(:option, include_blank, :value => '').safe_concat(option_tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
if prompt = options.delete(:prompt)
|
if prompt = options.delete(:prompt)
|
||||||
|
|
|
@ -224,6 +224,12 @@ class FormTagHelperTest < ActionView::TestCase
|
||||||
expected = %(<select id="places" name="places"><option value=""></option><option>Home</option><option>Work</option><option>Pub</option></select>)
|
expected = %(<select id="places" name="places"><option value=""></option><option>Home</option><option>Work</option><option>Pub</option></select>)
|
||||||
assert_dom_equal expected, actual
|
assert_dom_equal expected, actual
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_select_tag_with_include_blank_string
|
||||||
|
actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>".html_safe, :include_blank => 'Choose'
|
||||||
|
expected = %(<select id="places" name="places"><option value="">Choose</option><option>Home</option><option>Work</option><option>Pub</option></select>)
|
||||||
|
assert_dom_equal expected, actual
|
||||||
|
end
|
||||||
|
|
||||||
def test_select_tag_with_prompt
|
def test_select_tag_with_prompt
|
||||||
actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>".html_safe, :prompt => "string"
|
actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>".html_safe, :prompt => "string"
|
||||||
|
|
Loading…
Reference in a new issue