mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added that JavaScriptHelper#link_to_function will honor existing :onclick definitions when adding the function call [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3364 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
00541f263b
commit
341d34cd50
3 changed files with 11 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added that JavaScriptHelper#link_to_function will honor existing :onclick definitions when adding the function call [DHH]
|
||||
|
||||
* Added :disable_with option to FormTagHelper#submit_tag to allow for easily disabled submit buttons with different text [DHH]
|
||||
|
||||
* Make auto_link handle nil by returning quickly if blank? [Scott Barron]
|
||||
|
|
|
@ -48,9 +48,13 @@ module ActionView
|
|||
# link_to_function "Greeting", "alert('Hello world!')"
|
||||
# link_to_function(image_tag("delete"), "if confirm('Really?'){ do_delete(); }")
|
||||
def link_to_function(name, function, html_options = {})
|
||||
html_options.symbolize_keys!
|
||||
content_tag(
|
||||
"a", name,
|
||||
{:href => "#", :onclick => "#{function}; return false;"}.merge(html_options.symbolize_keys)
|
||||
html_options.merge({
|
||||
:href => html_options[:href] || "#",
|
||||
:onclick => "#{function};#{html_options[:onclick] ? " #{html_options[:onclick]};" : ""} return false;"
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -26,4 +26,8 @@ class JavaScriptHelperTest < Test::Unit::TestCase
|
|||
link_to_function("Greeting", "alert('Hello world!')")
|
||||
end
|
||||
|
||||
def test_link_to_function_with_existing_onclick
|
||||
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); confirm('Sanity!'); return false;">Greeting</a>),
|
||||
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue