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/02/22 12:20:14 UTC

git commit: WICKET-4236 Use JQuery as a backing library for Wicket's JavaScript code

Updated Branches:
  refs/heads/master b80e225f1 -> 18855d876


WICKET-4236 Use JQuery as a backing library for Wicket's JavaScript code

Fix serialization of multi values <select>.
Update the test cases to the new serialization format - as jQuery.serializeArray().


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

Branch: refs/heads/master
Commit: 18855d8766b453bdbf51584533ceda3d020e1e9c
Parents: b80e225
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Feb 22 12:18:16 2012 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Feb 22 12:18:16 2012 +0100

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js       |   10 +-
 wicket-core/src/test/js/form.js                    |  116 ++++++---------
 2 files changed, 53 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/18855d87/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 24eae3d..8fdbeeb 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
@@ -1163,7 +1163,15 @@
 					var $select = jQuery(select);
 					if ($select.length > 0 && $select.prop('disabled') === false) {
 						var name = $select.attr('name');
-						result.push( { name: name, value: $select.val() } );
+						var values = $select.val();
+						if (jQuery.isArray(values)) {
+							for (var v = 0; v < values.length; v++) {
+								var value = values[v];
+								result.push( { name: name, value: value } );
+							}
+						} else {
+							result.push( { name: name, value: values } );
+						}
 					}
 				}
 				return result;

http://git-wip-us.apache.org/repos/asf/wicket/blob/18855d87/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 b41bb5e..1700120 100644
--- a/wicket-core/src/test/js/form.js
+++ b/wicket-core/src/test/js/form.js
@@ -17,35 +17,6 @@
 
 jQuery(document).ready(function() {
 
-	/**
-	 * Extends oldObject with the properties from newObject.
-	 * If there is already a property with the same name then the
-	 * values are collected in an array
-	 *
-	 * @param oldObject {Object} the object to extend
-	 * @param newObject {Object} the object to extend from
-	 * @returns {Object} the object with all properties
-	 */
-	var extend = function (oldObject, newObject) {
-
-		for (var prop in newObject) {
-
-			if (!oldObject[prop]) {
-				oldObject[prop] = newObject[prop];
-			}
-			else if (jQuery.isArray(oldObject[prop])) {
-				oldObject[prop].push(newObject[prop]);
-			}
-			else {
-				oldObject[prop] = [ oldObject[prop], newObject[prop] ];
-			}
-		}
-
-		return oldObject;
-	}
-
-	var existingId = 'testElement';
-
 	module("encode");
 
 	test("Wicket.Form.encode ", function() {
@@ -82,42 +53,45 @@ jQuery(document).ready(function() {
 	test('Wicket.Form.serializeInput - input element', function() {
 		expect(1);
 
-		var queryString = {};
+		var actual = [];
 		jQuery('#testForm input').each(function() {
 			var serialized = Wicket.Form.serializeInput(this);
-			queryString = extend(queryString, serialized);
+			actual = actual.concat(serialized);
 		});
 
-		var expected = {
-			"textInput": "textValue",
-			"textUTFInput": "нещо на български",
-			"checkBoxInput1": "cbValue1",
-			"checkBoxInput3": "cbValue3",
-			"radioInput": "radioValue1",
-			"emailInput": "m@g.com",
-			"urlInput": "http://example.com",
-			"searchInput": "wicket",
-			"rangeInput": "67",
-			"numberInput": "16",
-			"colorInput": "123456"
-		};
-		deepEqual(queryString, expected);
+		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"             }
+		];
+		deepEqual(actual, expected);
 	});
 
 
 	test('Wicket.Form.serializeInput - textarea element', function() {
 		expect(1);
 
-		var queryString = {};
+		var actual = [];
 		jQuery('#testForm textarea').each(function() {
 			var serialized = Wicket.Form.serializeInput(this);
-			queryString = extend(queryString, serialized);
+			actual = actual.concat(serialized);
 		});
 
-		var expected = {
-			"textArea": "some text"
-		};
-		deepEqual(queryString, expected);
+		var expected = [
+			{
+				name: "textArea",
+				value: "some text"
+			}
+		];
+		deepEqual(actual, expected);
 	});
 
 	module('Wicket.Form.serializeElement');
@@ -129,31 +103,29 @@ jQuery(document).ready(function() {
 
 		expect(1);
 
-		var queryString = {};
+		var actual = [];
 		jQuery('input, textarea, select', jQuery('#testForm')).each(function() {
 			var serialized = Wicket.Form.serializeElement(this);
-			queryString = extend(queryString, serialized);
+			actual = actual.concat(serialized);
 		});
 
-		var expected = {
-			"textInput": "textValue",
-			"checkBoxInput1": "cbValue1",
-			"checkBoxInput3": "cbValue3",
-			"radioInput": "radioValue1",
-			"emailInput": "m@g.com",
-			"urlInput": "http://example.com",
-			"searchInput": "wicket",
-			"rangeInput": "67",
-			"numberInput": "16",
-			"colorInput": "123456",
-			"multipleSelect": [
-				"0",
-				"2"
-			],
-			"select": "0",
-			"textArea": "some text"
-		};
-		deepEqual(queryString, expected);
+		var expected = [
+			{ name: "textInput",      value: "textValue"          },
+			{ 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);
 
 		Wicket.Form.excludeFromAjaxSerialization = null;
 	});