You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/07/26 11:00:18 UTC
git commit: WICKET-4673 JavaScript error when submitting nested
multipart form
Updated Branches:
refs/heads/master 1d87d3ad5 -> b47116273
WICKET-4673 JavaScript error when submitting nested multipart form
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b4711627
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b4711627
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b4711627
Branch: refs/heads/master
Commit: b471162730c437ccc13fd13f810b0e6f2c95b2dc
Parents: 1d87d3a
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Jul 26 11:59:28 2012 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Jul 26 11:59:28 2012 +0300
----------------------------------------------------------------------
.../wicket/ajax/res/js/wicket-ajax-jquery.js | 36 +++++++++++----
1 files changed, 26 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/b4711627/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 7bab495..71a77f7 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -96,7 +96,7 @@
* Helper method that serializes HtmlDocument to string and then
* creates a DOMDocument by parsing this string.
* It is used as a workaround for the problem described at https://issues.apache.org/jira/browse/WICKET-4332
- * @param envelope (DispHtmlDocument) the document object created by IE from the XML response in the iframe
+ * @param htmlDocument (DispHtmlDocument) the document object created by IE from the XML response in the iframe
*/
htmlToDomDocument = function (htmlDocument) {
var xmlAsString = htmlDocument.body.outerText;
@@ -702,16 +702,29 @@
* this function will post the form using an iframe instead of the regular ajax call
* and bridge the output - transparently making this work as if it was an ajax call.
*
- * @param {Object} attrs - the ajax request attributes
+ * @param {Object} context - the context for the ajax call (request attributes + steps)
*/
- submitMultipartForm: function (attrs) {
+ submitMultipartForm: function (context) {
+ var attrs = context.attrs;
var form = Wicket.$(attrs.f);
if (!form) {
Wicket.Log.error("Wicket.Ajax.Call.submitForm: Trying to submit form with id '" + attrs.f + "' that is not in document.");
return;
}
+ // find root form
+ if (form.tagName.toLowerCase() !== "form") {
+ do {
+ form = form.parentNode;
+ } while(form.tagName.toLowerCase() != "form" && form !== document.body)
+ }
+
+ if (form.tagName.toLowerCase() !== "form") {
+ Wicket.Log.error("Cannot submit form with id " + attrs.f + " because there is no form element in the hierarchy.");
+ return false;
+ }
+
var submittingAttribute = 'data-wicket-submitting';
if (form.onsubmit && !form.getAttribute(submittingAttribute)) {
@@ -726,8 +739,6 @@
}
}
- var multipart = true;
-
var originalFormAction = form.action;
var originalFormTarget = form.target;
var originalFormMethod = form.method;
@@ -759,7 +770,7 @@
// install handler to deal with the ajax response
// ... we add the onload event after form submit because chrome fires it prematurely
- Wicket.Event.add(iframe, "load.handleMultipartComplete", jQuery.proxy(this.handleMultipartComplete, this), attrs);
+ Wicket.Event.add(iframe, "load.handleMultipartComplete", jQuery.proxy(this.handleMultipartComplete, this), context);
// handled, restore state and return true
form.action = originalFormAction;
@@ -794,11 +805,16 @@
// remove the event
jQuery(iframe).off("load.handleMultipartComplete");
- // remove the iframe and button elements
- window.setTimeout(function () {
+ context.steps.push(function(notify) {
+ // remove the iframe and button elements
jQuery('#'+iframe.id + '-btn').remove();
jQuery(iframe).remove();
- }, 1);
+ });
+
+ var executer = new FunctionsExecuter(context.steps);
+ executer.start();
+
+ this.done();
},
// Processes the response
@@ -819,7 +835,7 @@
// the root element must be <ajax-response
if (isUndef(root) || root.tagName !== "ajax-response") {
- this.failure("Could not find root <ajax-response> element");
+ this.failure(context, null, "Could not find root <ajax-response> element", null);
return;
}