Created
October 22, 2010 02:44
-
-
Save champierre/639832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** form_tag_helper.rb 2010-10-22 10:24:55.000000000 +0900 | |
--- form_tag_helper_jishiha.rb 2010-10-22 11:16:43.000000000 +0900 | |
*************** | |
*** 409,414 **** | |
--- 409,415 ---- | |
# prompt with the question specified. If the user accepts, the form is | |
# processed normally, otherwise no action is taken. | |
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input. | |
+ # * <tt>:disable</tt> - If set to true, the submit button is disabled when the form is submitted. | |
# * Any other key creates standard HTML options for the tag. | |
# | |
# ==== Examples | |
*************** | |
*** 423,428 **** | |
--- 424,432 ---- | |
# | |
# image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button") | |
# # => <input class="agree_disagree_button" disabled="disabled" src="/images/agree.png" type="image" /> | |
+ # | |
+ # image_submit_tag("purchase.png", :disable => true) | |
+ # # => <input onclick="this.disabled = true;result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.disabled = false; }return result;"src="/images/purchase.png" type="image" /> | |
def image_submit_tag(source, options = {}) | |
options.stringify_keys! | |
*************** | |
*** 430,435 **** | |
--- 434,447 ---- | |
add_confirm_to_attributes!(options, 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment