From e658064759d54e0d43872a5430ad0381366b0bcd Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Thu, 23 Dec 2010 04:26:31 +0000 Subject: #995854 by rfay, effulgentsia, sun, merlinofchaos, Damien Tournoud, manimejia: Fixed #ajax doesn't work at all if a file element (or enctype => 'multipart/form-data') is included in the form --- misc/ajax.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'misc') diff --git a/misc/ajax.js b/misc/ajax.js index 57a16048e..b17e64a9f 100644 --- a/misc/ajax.js +++ b/misc/ajax.js @@ -152,9 +152,9 @@ Drupal.ajax = function (base, element, element_settings) { ajax.ajaxing = true; return ajax.beforeSubmit(form_values, element_settings, options); }, - beforeSend: function (xmlhttprequest) { + beforeSend: function (xmlhttprequest, options) { ajax.ajaxing = true; - return ajax.beforeSend(xmlhttprequest, ajax.options); + return ajax.beforeSend(xmlhttprequest, options); }, success: function (response, status) { // Sanity check for browser support (object expected). @@ -318,7 +318,20 @@ Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) { * Prepare the AJAX request before it is sent. */ Drupal.ajax.prototype.beforeSend = function (xmlhttprequest, options) { - // Disable the element that received the change. + // Disable the element that received the change to prevent user interface + // interaction while the AJAX request is in progress. ajax.ajaxing prevents + // the element from triggering a new request, but does not prevent the user + // from changing its value. + // Forms without file inputs are already serialized before this function is + // called. Forms with file inputs use an IFRAME to perform a POST request + // similar to a browser, so disabled elements are not contained in the + // submitted values. Therefore, we manually add the element's value to + // options.extraData. + var v = $.fieldValue(this.element); + if (v !== null) { + options.extraData = options.extraData || {}; + options.extraData[this.element.name] = v; + } $(this.element).addClass('progress-disabled').attr('disabled', true); // Insert progressbar or throbber. -- cgit v1.2.3