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 2015/08/11 13:27:07 UTC

wicket git commit: WICKET-5948 wicket-ajax.js probably doesn't traverse the children of
or

Repository: wicket
Updated Branches:
  refs/heads/wicket-6.x 345c9138b -> 031dee240


WICKET-5948 wicket-ajax.js probably doesn't traverse the children of <div> or <span>

Serialize all HTMLFormElement children of the serialized div/span (FormComponentPanel)


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/031dee24
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/031dee24
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/031dee24

Branch: refs/heads/wicket-6.x
Commit: 031dee24049393f7ad30b0c7231b48a6ed46742f
Parents: 345c913
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Aug 11 14:25:32 2015 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Aug 11 14:26:51 2015 +0300

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 47 +++++++++++++-------
 wicket-core/src/test/js/all.html                |  4 ++
 wicket-core/src/test/js/form.js                 | 25 +++++++++++
 3 files changed, 61 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/031dee24/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 91e7cff..916cd25 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
@@ -49,7 +49,8 @@
 		getAjaxBaseUrl,
 		isUndef,
 		replaceAll,
-		htmlToDomDocument;
+		htmlToDomDocument,
+		nodeListToArray;
 
 	isUndef = function (target) {
 		return (typeof(target) === 'undefined' || target === null);
@@ -98,6 +99,23 @@
 	};
 
 	/**
+	 * Converts a NodeList to an Array
+	 *
+	 * @param nodeList The NodeList to convert
+	 * @returns {Array} The array with document nodes
+	 */
+	nodeListToArray = function (nodeList) {
+		var arr = [],
+			nodeId;
+		if (nodeList && nodeList.length) {
+			for (nodeId = 0; nodeId < nodeList.length; nodeId++) {
+				arr.push(nodeList.item(nodeId));
+			}
+		}
+		return arr;
+	};
+
+	/**
 	 * Functions executer takes array of functions and executes them.
 	 * The functions are executed one by one as far as the return value is FunctionsExecuter.DONE.
 	 * If the return value is FunctionsExecuter.ASYNC or undefined then the execution of
@@ -1531,25 +1549,24 @@
 				} else if (tag === "input" || tag === "textarea") {
 					return Wicket.Form.serializeInput(element);
 				} else {
-					return [];
+					var elements = nodeListToArray(element.getElementsByTagName("input"));
+					elements = elements.concat(nodeListToArray(element.getElementsByTagName("select")));
+					elements = elements.concat(nodeListToArray(element.getElementsByTagName("textarea")));
+
+					var result = [];
+					for (var i = 0; i < elements.length; ++i) {
+						var el = elements[i];
+						if (el.name && el.name !== "") {
+							result = result.concat(Wicket.Form.serializeElement(el));
+						}
+					}
+					return result;
 				}
 			},
 
 			serializeForm: function (form) {
 				var result = [],
-					elements,
-					nodeListToArray,
-					nodeId;
-
-				nodeListToArray = function (nodeList) {
-					var arr = [];
-					if (nodeList && nodeList.length) {
-						for (nodeId = 0; nodeId < nodeList.length; nodeId++) {
-							arr.push(nodeList.item(nodeId));
-						}
-					}
-					return arr;
-				};
+					elements;
 
 				if (form) {
 					if (form.tagName.toLowerCase() === 'form') {

http://git-wip-us.apache.org/repos/asf/wicket/blob/031dee24/wicket-core/src/test/js/all.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/all.html b/wicket-core/src/test/js/all.html
index 6a03f52..d1185f9 100644
--- a/wicket-core/src/test/js/all.html
+++ b/wicket-core/src/test/js/all.html
@@ -112,6 +112,8 @@
 		-->
 		<form id="testForm" action="actionUrl">
 
+			<div id="nonHtmlFormElement">
+
 			<input type="text" id="textInputId" name="textInput" value="textValue"/>
 
 			<input type="text" id="textInputUTFId" name="textUTFInput" value="нещо на български"/>
@@ -149,6 +151,8 @@
 
 			<textarea name="textArea">some text</textarea>
 
+			</div>
+
 		</form>
 
 		<!-- WICKET-4673 Ajax submit of nested form -->

http://git-wip-us.apache.org/repos/asf/wicket/blob/031dee24/wicket-core/src/test/js/form.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/form.js b/wicket-core/src/test/js/form.js
index 99f55ab..7e309a3 100644
--- a/wicket-core/src/test/js/form.js
+++ b/wicket-core/src/test/js/form.js
@@ -134,6 +134,31 @@ jQuery(document).ready(function() {
 		Wicket.Form.excludeFromAjaxSerialization = null;
 	});
 
+	test("Wicket.Form.serializeElement should serialize the HTMLFormElement's which a children of a non-HTMLFormElement", function() {
+		expect(1);
+
+		var actual = Wicket.Form.serializeElement('nonHtmlFormElement');
+
+		var expected = [
+			{ name: "textInput",      value: "textValue"          },
+			{ name: "textUTFInput",      value: "нещо на български"          },
+			{ name: "checkBoxInput1", value: "cbValue1"           },
+			{ name: "checkBoxInput3", value: "cbValue3"           },
+			{ name: "radioInput",     value: "radioValue1"        },
+			{ name: "emailInput",     value: "m@g.com"            },
+			{ name: "urlInput",       value: "http://example.com" },
+			{ name: "searchInput",    value: "wicket"             },
+			{ name: "rangeInput",     value: "67"                 },
+			{ name: "numberInput",    value: "16"                 },
+			{ name: "colorInput",     value: "#123456"            },
+			{ name: "multipleSelect", value: "0"                  },
+			{ name: "multipleSelect", value: "2"                  },
+			{ name: "select",         value: "0"                  },
+			{ name: "textArea",       value: "some text"          }
+		];
+		deepEqual(actual, expected);
+	});
+
 	module('Wicket.Form.serializeForm');
 
 	test('Wicket.Form.serialize - form element WITHOUT searching for the parent form', function() {