Author: mgrigorov
Date: Tue Nov 22 10:55:15 2011
New Revision: 1204912

URL: http://svn.apache.org/viewvc?rev=1204912&view=rev
Log:
WICKET-4236 Use JQuery as a backing library for Wicket's JavaScript code

Reimplement Wicket.Form.serializeInput() with jQuery.
The difference in the test expectation is that jQuery doesn't encode '+' to 
'%20'


Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
    wicket/trunk/wicket-core/src/test/js/form.js

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js?rev=1204912&r1=1204911&r2=1204912&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
 Tue Nov 22 10:55:15 2011
@@ -1115,19 +1115,20 @@ jQuery.noConflict();
                            return result;
                        },
 
-                       // this function intentionally ignores image and submit 
inputs
+                       /**
+                        * Serializes a form element to a key=value string in 
URL encoded notation.
+                        * Note: this function intentionally ignores image and 
submit inputs.
+                        *
+                        * @param {HtmlFormElement} input - the form element to 
serialize
+                        * @return the URL encoded key=value pair or empty 
string if the form element is disabled.
+                        */
                        serializeInput: function (input) {
-                           var type = input.type.toLowerCase();
-                           if ((type === "checkbox" || type === "radio") && 
input.checked) {
-                               return Wicket.Form.encode(input.name) + "=" + 
Wicket.Form.encode(input.value) + "&";
-                           } else if (type === "text" || type === "password" 
|| type === "hidden" || type === "textarea" || type === "search" ||
-                                       type === "email" || type === "url" || 
type === "range" || type === "tel" ||
-                                       type === "date" || type === "datetime" 
|| type === "month" || type === "week" ||        type === "week" ||
-                                       type === "datetime-local" || type === 
"number" || type === "color") {
-                                       return Wicket.Form.encode(input.name) + 
"=" + Wicket.Form.encode(input.value) + "&";
-                               } else {
-                                       return "";
+                               var result = "";
+                               if (input && input.type && !(input.type === 
'image' || input.type === 'submit')) { 
+                               result = jQuery(input).serialize();
                            }
+                           if (result) result += "&";
+                           return result;
                        },
 
                        //list of item to exclude from serialization

Modified: wicket/trunk/wicket-core/src/test/js/form.js
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/js/form.js?rev=1204912&r1=1204911&r2=1204912&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/test/js/form.js (original)
+++ wicket/trunk/wicket-core/src/test/js/form.js Tue Nov 22 10:55:15 2011
@@ -58,7 +58,7 @@ jQuery(document).ready(function() {
                        queryString += Wicket.Form.serializeInput(this);
                });
 
-               equals(queryString, 
'textInput=textValue&textUTFInput=%D0%BD%D0%B5%D1%89%D0%BE%20%D0%BD%D0%B0%20%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=123456&');
+               equals(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=123456&');
        });
 
 
@@ -70,7 +70,7 @@ jQuery(document).ready(function() {
                        queryString += Wicket.Form.serializeInput(this);
                });
 
-               equals(queryString, 'textArea=some%20text&');
+               equals(queryString, 'textArea=some+text&');
        });
 
        module('Wicket.Form.serializeElement');
@@ -87,7 +87,7 @@ jQuery(document).ready(function() {
                        queryString += Wicket.Form.serializeElement(this);
                });
 
-               equals(queryString, 
'textInput=textValue&checkBoxInput1=cbValue1&checkBoxInput3=cbValue3&radioInput=radioValue1&emailInput=m%40g.com&urlInput=http%3A%2F%2Fexample.com&searchInput=wicket&rangeInput=67&numberInput=16&colorInput=123456&multipleSelect=0&multipleSelect=2&select=0&textArea=some%20text&');
+               equals(queryString, 
'textInput=textValue&checkBoxInput1=cbValue1&checkBoxInput3=cbValue3&radioInput=radioValue1&emailInput=m%40g.com&urlInput=http%3A%2F%2Fexample.com&searchInput=wicket&rangeInput=67&numberInput=16&colorInput=123456&multipleSelect=0&multipleSelect=2&select=0&textArea=some+text&');
 
                Wicket.Form.excludeFromAjaxSerialization = null;
        });
@@ -115,7 +115,7 @@ jQuery(document).ready(function() {
                        queryString = Wicket.Form.serialize(this, 
dontTryToFindRootForm);
                });
 
-               equals(queryString, 
'textInput=textValue&textUTFInput=%D0%BD%D0%B5%D1%89%D0%BE%20%D0%BD%D0%B0%20%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=123456&multipleSelect=0&multipleSelect=2&select=0&textArea=some%20text&',
 'Wicket.Form.serialize should serialize the whole form when an element is 
passed and the parent form should be searched');
+               equals(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=123456&multipleSelect=0&multipleSelect=2&select=0&textArea=some+text&',
 'Wicket.Form.serialize should serialize the whole form when an element is 
passed and the parent form should be searched');
        });
 
 
@@ -128,7 +128,7 @@ jQuery(document).ready(function() {
                        queryString = Wicket.Form.serialize(this, 
dontTryToFindRootForm);
                });
 
-               equals(queryString, 
'textInput=textValue&textUTFInput=%D0%BD%D0%B5%D1%89%D0%BE%20%D0%BD%D0%B0%20%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=123456&multipleSelect=0&multipleSelect=2&select=0&textArea=some%20text&',
 'Wicket.Form.serialize should serialize the whole form when a the form itself 
is passed');
+               equals(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=123456&multipleSelect=0&multipleSelect=2&select=0&textArea=some+text&',
 'Wicket.Form.serialize should serialize the whole form when a the form itself 
is passed');
        });
 
 });


Reply via email to