a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith* Extends IO to enable HTML form data serialization, when specified
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith* in the transaction's configuration object.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith* @submodule io-form
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith * Method to enumerate through an HTML form's elements collection
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith * and return a string comprised of key-value pairs.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith * @method _serialize
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith * @param {Object} c - YUI form node or HTML form id.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith * @param {String} s - Key-value data defined in the configuration object.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith * @return {String}
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith _serialize: function(c, s) {
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // Iterate over the form elements collection to construct the
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // label-value pairs.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith for (i = 0, il = f.elements.length; i < il; ++i) {
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith if (df ? n : n && !d) {
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith switch (e.type) {
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // Safari, Opera, FF all default options.value from .text if
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // value attribute not specified in markup
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'select-one':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'select-multiple':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'radio':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'checkbox':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'file':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // stub case as XMLHttpRequest will only send the file path as a string.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // stub case for fieldset element which returns undefined.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'reset':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // stub case for input type reset button.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'button':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith // stub case for input type button elements.
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith case 'submit':
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith Y.log('HTML form serialized. The value is: ' + data.join('&'), 'info', 'io');
a23a8b9cc849a2aa697a3820f45e1b0f652f4e53Luke Smith return s ? data.join('&') + "&" + s : data.join('&');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}, '@VERSION@' ,{requires:['io-base','node-base']});