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/03/01 16:27:35 UTC
[2/2] git commit: Add test for serializing nested forms
Add test for serializing nested forms
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2c490f6b
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2c490f6b
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2c490f6b
Branch: refs/heads/master
Commit: 2c490f6bbe4c0f0584751b183adba38d3dfc9e42
Parents: 81e092c
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Mar 1 17:26:58 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Mar 1 17:26:58 2012 +0200
----------------------------------------------------------------------
.../wicket/ajax/res/js/wicket-ajax-jquery.js | 14 ++--
wicket-core/src/test/js/form.js | 55 ++++++++++++++-
2 files changed, 62 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/2c490f6b/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 52d1750..3cfb02b 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
@@ -1237,12 +1237,14 @@
return arr;
};
- if (form && form.tagName.toLowerCase() === 'form') {
- elements = form.elements;
- } else {
- elements = nodeListToArray(form.getElementsByTagName("input"));
- elements = elements.concat(nodeListToArray(form.getElementsByTagName("select")));
- elements = elements.concat(nodeListToArray(form.getElementsByTagName("textarea")));
+ if (form) {
+ if (form.tagName.toLowerCase() === 'form') {
+ elements = form.elements;
+ } else {
+ elements = nodeListToArray(form.getElementsByTagName("input"));
+ elements = elements.concat(nodeListToArray(form.getElementsByTagName("select")));
+ elements = elements.concat(nodeListToArray(form.getElementsByTagName("textarea")));
+ }
}
for (var i = 0; i < elements.length; ++i) {
http://git-wip-us.apache.org/repos/asf/wicket/blob/2c490f6b/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 b5c9620..bf298b2 100644
--- a/wicket-core/src/test/js/form.js
+++ b/wicket-core/src/test/js/form.js
@@ -130,7 +130,7 @@ jQuery(document).ready(function() {
Wicket.Form.excludeFromAjaxSerialization = null;
});
- module('Wicket.Form.serialize');
+ module('Wicket.Form.serializeForm');
test('Wicket.Form.serialize - form element WITHOUT searching for the parent form', function() {
@@ -172,4 +172,57 @@ jQuery(document).ready(function() {
equal(queryString, 'textInput=textValue&textUTFInput=%D0%BD%D0%B5%D1%89%D0%BE+%D0%BD%D0%B0+%D0%B1%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8&checkBoxInput1=cbValue1&checkBoxInput3=cbValue3&radioInput=radioValue1&emailInput=m%40g.com&urlInput=http%3A%2F%2Fexample.com&searchInput=wicket&rangeInput=67&numberInput=16&colorInput=%23123456&multipleSelect=0&multipleSelect=2&select=0&textArea=some+text', 'Wicket.Form.serialize should serialize the whole form when a the form itself is passed');
});
+ test('Wicket.Form.serializeForm - serialize nested form (div element)', function() {
+
+ expect(1);
+
+ var $nestedForm = jQuery(
+ "<form>" +
+ "<div id='nestedForm'>" +
+ "<input type='text' name='textInput' value='textInputValue'/>" +
+ "<input type='checkbox' name='checkboxInput' value='checkboxInputValue' checked/>" +
+ "<input type='checkbox' name='checkboxInput' value='checkboxInputValue' checked/>" + // second time
+ "<input type='radio' name='radioInput' value='radioInputValue' checked/>" +
+ "<textarea name='textareaInput'>textareaValue</textarea>" +
+ "<select name='selectInput'>" +
+ "<option value='selectInputValue1'>Value 1</option>" +
+ "<option value='selectInputValue2' selected>Value 2</option>" +
+ "</select>" +
+ "</div>" +
+ "</form>"
+ );
+
+ jQuery("#qunit-fixture").append($nestedForm);
+ var nestedFormDiv = Wicket.$('nestedForm');
+ var actual = Wicket.Form.serializeForm(nestedFormDiv);
+
+ var expected = [
+ {
+ "name": "textInput",
+ "value": "textInputValue"
+ },
+ {
+ "name": "checkboxInput",
+ "value": "checkboxInputValue"
+ },
+ {
+ "name": "checkboxInput",
+ "value": "checkboxInputValue"
+ },
+ {
+ "name": "radioInput",
+ "value": "radioInputValue"
+ },
+ {
+ "name": "selectInput",
+ "value": "selectInputValue2"
+ },
+ {
+ "name": "textareaInput",
+ "value": "textareaValue"
+ }
+ ];
+ deepEqual(actual, expected, "Nested form successfully serialized");
+ });
+
});