Skip to content

Commit

Permalink
Merge pull request #1736 from krororo/fix-ignore-newline
Browse files Browse the repository at this point in the history
fix textarea value with leading newline
  • Loading branch information
ujifgc committed Aug 7, 2014
2 parents 6358252 + 1af5f3d commit 0076c25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion padrino-helpers/lib/padrino-helpers/form_helpers.rb
Expand Up @@ -397,7 +397,7 @@ def hidden_field_tag(name, options={})
# text_area_tag :username, :class => 'long', :value => "Demo?"
#
def text_area_tag(name, options={})
inner_html = options.delete(:value).to_s
inner_html = "\n#{options.delete(:value)}"
options = { :name => name, :rows => "", :cols => "" }.update(options)
content_tag(:textarea, inner_html, options)
end
Expand Down
6 changes: 6 additions & 0 deletions padrino-helpers/test/test_form_helpers.rb
Expand Up @@ -498,6 +498,12 @@ def protect_from_csrf; false; end
assert_has_tag(:textarea, :content => "a test", :name => 'about', :rows => "5", :cols => "6") { actual_html }
end

it 'should insert newline to before of content' do
actual_html = text_area_tag(:about, :value => "\na test")
assert_has_tag(:textarea, :content => "\na test", :name => 'about') { actual_html }
assert_match(%r{<textarea[^>]*>\n\na test</textarea>}, actual_html)
end

it 'should display text area in erb' do
visit '/erb/form_tag'
assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
Expand Down

0 comments on commit 0076c25

Please sign in to comment.