public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
The FormTagHelper#submit_tag helper will now pass along the original value of 
the submit button to the params if the :disable_with option is used 
[status:committed #633]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
jfernandez (author)
Wed Jul 16 08:29:22 -0700 2008
dhh (committer)
Tue Sep 09 22:02:23 -0700 2008
commit  184cf27b1244734a33833cf2cb9b8062e9ee8a63
tree    40dab74c247145fbd72a52fd741e197a622091a8
parent  6dc9173a63fdd8510b95e6de189139046b2a0a30
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
0
 
0
+* Fixed FormTagHelper#submit_tag with :disable_with option wouldn't submit the button's value when was clicked #633 [Jose Fernandez]
0
+
0
 * Stopped logging template compiles as it only clogs up the log [DHH]
0
 
0
 * Changed the X-Runtime header to report in milliseconds [DHH]
...
116
117
118
119
 
120
121
122
...
351
352
353
354
355
356
357
358
359
360
361
 
 
 
 
 
362
363
364
365
366
 
367
368
369
...
116
117
118
 
119
120
121
122
...
351
352
353
 
 
 
 
 
 
 
 
354
355
356
357
358
359
360
361
362
 
363
364
365
366
0
@@ -116,7 +116,7 @@ module ActionView
0
 
0
       # Creates a label field
0
       #
0
-      # ==== Options
0
+      # ==== Options  
0
       # * Creates standard HTML attributes for the tag.
0
       #
0
       # ==== Examples
0
@@ -351,19 +351,16 @@ module ActionView
0
           disable_with = "this.value='#{disable_with}'"
0
           disable_with << ";#{options.delete('onclick')}" if options['onclick']
0
           
0
-          options["onclick"] = [
0
-            "this.setAttribute('originalValue', this.value)",
0
-            "this.disabled=true",
0
-            disable_with,
0
-            "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit())",
0
-            "if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false }",
0
-            "return result;",
0
-          ].join(";")
0
+          options["onclick"]  = "if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }"
0
+          options["onclick"] << "else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }"
0
+          options["onclick"] << "this.setAttribute('originalValue', this.value);this.disabled = true;#{disable_with};"
0
+          options["onclick"] << "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());"
0
+          options["onclick"] << "if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;"
0
         end
0
 
0
         if confirm = options.delete("confirm")
0
           options["onclick"] ||= ''
0
-          options["onclick"] += "return #{confirm_javascript_function(confirm)};"
0
+          options["onclick"] << "return #{confirm_javascript_function(confirm)};"
0
         end
0
 
0
         tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
...
223
224
225
226
 
227
228
229
230
231
232
233
 
234
235
236
...
223
224
225
 
226
227
228
229
230
231
232
 
233
234
235
236
0
@@ -223,14 +223,14 @@ class FormTagHelperTest < ActionView::TestCase
0
 
0
   def test_submit_tag
0
     assert_dom_equal(
0
-      %(<input name='commit' type='submit' value='Save' onclick="this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false };return result;" />),
0
+      %(<input name='commit' type='submit' value='Save' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
0
       submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
0
     )
0
   end
0
 
0
   def test_submit_tag_with_no_onclick_options
0
     assert_dom_equal(
0
-      %(<input name='commit' type='submit' value='Save' onclick="this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false };return result;" />),
0
+      %(<input name='commit' type='submit' value='Save' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
0
       submit_tag("Save", :disable_with => "Saving...")
0
     )
0
   end

Comments