Hi all,
After searching for a way to set the input type of a submit tag to
image when using submit_to_remote I realized that the method call
given below, while seemingly valid, wasn’t working since the method
button_to_function in actionpack/lib/action_view/helpers/
javascript_helper.rb was forcing the type to button.
-
The method call in the view:
<%=
submit_to_remote(
‘update_resource_img’,
‘Update Resource 2’,
:url => { :controller => ‘hello’, :action => ‘update’ },
:before => “$(‘loading’).style.display = ‘block’”,
:after => “return false”,
:html => { :src => ‘/images/button.gif’, :type => ‘image’ }
)
%> -
def button_to_function in action_view/helpers/javascript_helper.rb
does the following(note the :type => ‘button’) :
tag(:input, html_options.merge(:type => ‘button’, :value =>
name, :onclick => onclick)) -
It is my opinion (finally :p) that the def button_to_remote should
allow the input type to be either a button or an image since the w3c
page on form input control types states that the input type image
“Creates a graphical submit button.”
http://www.w3.org/TR/html401/interact/forms.html#h-17.4.1 -
Hence, to ensure that button_to_remote allows me to set the type of
either of button or image, I place the following in a file in
$RAILS_ROOT/lib and require it at the end of $RAILS_ROOT/config/
environment.rb
module ActionView
module Helpers
module JavaScriptHelper
def button_to_function(name, *args, &block)
html_options = args.extract_options!.symbolize_keys
function = block_given? ? update_page(&block) : args[0] || ''
onclick = "#{"#{html_options[:onclick]}; " if html_options
[:onclick]}#{function};"
html_options[:type] = 'button' if( !html_options[:type] ||
html_options[:type] !~ /^image|button$/i )
tag(:input, html_options.merge(:value => name, :onclick =>
onclick))
end
end
end
end
- Hope you guys have an opinion to share.
- Gautam
Programmer @ Azri