From f1c8b3ffc0d8dfd9dd2cb28c1e569d66d116cc9a Mon Sep 17 00:00:00 2001 From: Gilles van den Hoven Date: Wed, 17 May 2006 16:01:19 +0000 Subject: [PATCH] Fixxed the form serialize function as seen on the mailing list. --- ajax/ajax.js | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/ajax/ajax.js b/ajax/ajax.js index 257ae02..d3443cc 100644 --- a/ajax/ajax.js +++ b/ajax/ajax.js @@ -139,13 +139,29 @@ $.fn.load = function(a,o,f) { }; /** - * function: $.fn.formValues - * usage: $('#frmLogin').formValues() - * docs: Gets the form values and creates a key=>value array of the found values (only for ENABLED elements!) + * function: $.fn.formValues + * usage: $('#frmLogin').formValues() + * docs: Gets form values and creates a key=>value array of the found values (for ENABLED elements!) */ $.fn.formValues = function() { var a = []; - this.find("input[@type='submit'],input[@type='hidden'],textarea,input[@checked],input[@type='password'],input[@type='text'],option[@selected]").filter(":enabled").each(function() { + this.find("input,textarea,option") + .filter(":enabled") + .each(function() { + // + // Skip selects with options which aren't selected + if (((this.parentNode.type == 'select-one') || (this.parentNode.type == 'select-multiple')) && + (!this.selected)) + return; + + // + // Skip radio and checkbox elements which aren't checked + if (((this.type == 'radio') || (this.type == 'checkbox')) && + (!this.checked)) + return; + + // + // All other elements are valid ;) var o = {}; o.name = this.name || this.id || this.parentNode.name || this.parentNode.id; o.value = this.value; @@ -155,11 +171,11 @@ $.fn.formValues = function() { }; /** - * function: $.update - * usage: $.update('someJQueryObject', 'someurl', 'array'); - * docs: Mimics the ajaxUpdater from prototype. Posts the key=>value array to the url and - * puts the results from that call in the jQuery object specified. - * --> If you set the blnNoEval to true, the script tags are NOT evaluated. + * function: $.update + * usage: $.update('someJQueryObject', 'someurl', 'array'); + * docs: Mimics the ajaxUpdater from prototype. Posts the key=>value array to the url and + * puts the results from that call in the jQuery object specified. + * --> If you set the blnNoEval to true, the script tags are NOT evaluated. */ $.update = function(objElement, strURL, arrValues, fncCallback) { $.post(strURL, arrValues, function(strHTML) { @@ -170,7 +186,9 @@ $.update = function(objElement, strURL, arrValues, fncCallback) { // // Evaluate the scripts objElement.html(strHTML).find("script").each(function(){ - try { $.eval( this.text || this.textContent || this.innerHTML ); } catch(e){} + try { + $.eval( this.text || this.textContent || this.innerHTML ); + } catch(e) { } }); // -- 1.7.10.4