3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('io-form', function(Y) {
10 * Extends IO to enable HTML form data serialization, when specified
11 * in the transaction's configuration object.
17 var eUC = encodeURIComponent;
19 Y.mix(Y.IO.prototype, {
21 * Method to enumerate through an HTML form's elements collection
22 * and return a string comprised of key-value pairs.
27 * @param {Object} c - YUI form node or HTML form id.
28 * @param {String} s - Key-value data defined in the configuration object.
31 _serialize: function(c, s) {
33 df = c.useDisabled || false,
35 id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
36 e, f, n, v, d, i, il, j, jl, o;
40 c.id.setAttribute('id', id);
43 f = Y.config.doc.getElementById(id);
45 // Iterate over the form elements collection to construct the
47 for (i = 0, il = f.elements.length; i < il; ++i) {
52 if (df ? n : n && !d) {
57 // Safari, Opera, FF all default options.value from .text if
58 // value attribute not specified in markup
60 if (e.selectedIndex > -1) {
61 o = e.options[e.selectedIndex];
62 data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
65 case 'select-multiple':
66 if (e.selectedIndex > -1) {
67 for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
70 data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
82 // stub case as XMLHttpRequest will only send the file path as a string.
84 // stub case for fieldset element which returns undefined.
86 // stub case for input type reset button.
88 // stub case for input type button elements.
96 return s ? data.join('&') + "&" + s : data.join('&');
101 }, '3.5.0' ,{requires:['io-base','node-base']});