From 9a6171c09c2b73e2e3308821ab06f480af83d6ce Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Mon, 22 Sep 2008 22:24:32 +0000 Subject: [PATCH] added getFormValue method which accepts an HTML element or id and returns the value of the field regardless of it's type --- www/extras/yui-webgui/build/form/form.js | 125 +++++++++++++++-------- 1 file changed, 85 insertions(+), 40 deletions(-) diff --git a/www/extras/yui-webgui/build/form/form.js b/www/extras/yui-webgui/build/form/form.js index 89c6be4cd..38dad03a0 100644 --- a/www/extras/yui-webgui/build/form/form.js +++ b/www/extras/yui-webgui/build/form/form.js @@ -7,50 +7,10 @@ if (typeof WebGUI.Form == "undefined") { WebGUI.Form = {}; } - /** * This object contains generic form modification functions */ -/**************************************************************************** - * WebGUI.Form.toggleAllCheckboxesInForm ( formElement [, checkboxesName] ) - * Toggles all the checkboxes in the form, optionally limited by name. - * Will automatically set them all to "checked" the first time - */ -WebGUI.Form.toggleAllCheckboxesInForm - = function (formElement, checkboxesName) { - // Get the state to set - var oldState = WebGUI.Form.toggleAllCheckboxesState[formElement+checkboxesName] - var state = oldState ? "" : "checked"; - - for (var i = 0; i < formElement.elements.length; i++) { - var input = formElement.elements[i]; - if (!/^check/.test(input.type)) - continue; - if (checkboxesName && input.name != checkboxesName) - continue; - - // Change the state - input.checked = state; - // Run the appropriate scripts - if ( input.onchange ) - input.onchange(); - } - - // Update the saved state - WebGUI.Form.toggleAllCheckboxesState[formElement+checkboxesName] = state; - }; - - -/* - * WebGUI.Form.toggleAllCheckboxesState - * An object containing a hash of + : 0|1 to save - * the state of the toggled checkboxes. You can use this to set what the - * first run of toggleAllCheckboxesInForm will do. - */ -WebGUI.Form.toggleAllCheckboxesState = {}; - - /*********************************************************************************** * @description This method assembles the form label and value pairs and * constructs an encoded string. @@ -136,3 +96,88 @@ WebGUI.Form.buildQueryString = function ( formId, excludes ) { return sFormData; }; +/*********************************************************************************** + * @description This method gets the proper value of the form element passed in + * @method getFormValue + * @public + * @static + * @param {string || object} id or object of the form element to get the value of. + */ + +WebGUI.Form.getFormValue = function ( oElement ) { + + if(typeof oElement != 'object') oElement = document.getElementById(oElement); + + var oType = oElement.type; + var oValue = ""; + + switch(oType) { + case 'select-one': + case 'select-multiple': + for(var i=0; i+ : 0|1 to save + * the state of the toggled checkboxes. You can use this to set what the + * first run of toggleAllCheckboxesInForm will do. + */ +WebGUI.Form.toggleAllCheckboxesState = {}; +