Skip to content

Commit 8b147fb

Browse files
committed
Re-enable form fields if ajax:aborted:file handler returns false.
1 parent 9c8fc79 commit 8b147fb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/rails.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,15 @@
366366

367367
if (remote) {
368368
if (nonBlankFileInputs) {
369+
// slight timeout so that the submit button gets properly serialized
370+
// (make it easy for event handler to serialize form without disabled values)
369371
setTimeout(function(){ rails.disableFormElements(form); }, 13);
370-
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
372+
var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
373+
374+
// re-enable form elements if event bindings return false (canceling normal form submission)
375+
if (!aborted) { setTimeout(function(){ rails.enableFormElements(form); }, 13); }
376+
377+
return aborted;
371378
}
372379

373380
// If browser does not support submit bubbling, then this live-binding will be called before direct

0 commit comments

Comments
 (0)