Skip to content

Instantly share code, notes, and snippets.

@champierre
Created October 18, 2010 10:06
Show Gist options
  • Save champierre/631996 to your computer and use it in GitHub Desktop.
Save champierre/631996 to your computer and use it in GitHub Desktop.
module ActionView
module Helpers
module FormTagHelper
def image_submit_tag(source, options = {})
options.stringify_keys!
if confirm = options.delete("confirm")
options["onclick"] ||= ''
options["onclick"] += "return #{confirm_javascript_function(confirm)};"
end
if disable = options.delete("disable")
onclick = "#{options.delete('onclick')}" if options['onclick']
options["onclick"] = "this.setAttribute('originalValue', this.value);this.disabled = true;#{onclick};"
options["onclick"] << "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());"
options["onclick"] << "if (result == false) { this.disabled = false; }return result;"
end
tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment