// Initialize namespace if (typeof WebGUI == "undefined") { var WebGUI = {}; } 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. * @method buildQueryString * @public * @static * @param {string || object} form id or name attribute, or form object. * @param {object} object containing array of form elements to exclude. { id:[], name:[], classNames:[], type:[] } * @return {string} string of the HTML form field name and value pairs. */ WebGUI.Form.buildQueryString = function ( formId, excludes ) { var _isInArray = function ( value, array) { if(!array || !value) return 0; if(typeof array != 'object') return 0; for(var i = 0; i < array.length; i++) { if(array[i] == value) return 1; } return 0; }; var oForm = (document.getElementById(formId) || document.forms[formId]); var oElement, oName, oValue, oDisabled; var sFormData = ""; if(!excludes) { excludes = {}; } // Iterate over the form elements collection to construct the label-value pairs. for (var i=0; i