2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('io-form', function(Y) {
11 * Extends the IO base class to enable HTML form data serialization, when specified
12 * in the transaction's configuration object.
19 * @description Method to enumerate through an HTML form's elements collection
20 * and return a string comprised of key-value pairs.
25 * @param {object} c - YUI form node or HTML form id.
26 * @param {string} s - Transaction data defined in the configuration.
29 _serialize: function(c, s) {
30 var eUC = encodeURIComponent,
32 useDf = c.useDisabled || false,
34 id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
35 e, f, n, v, d, i, il, j, jl, o;
39 c.id.setAttribute('id', id);
42 f = Y.config.doc.getElementById(id);
44 // Iterate over the form elements collection to construct the
46 for (i = 0, il = f.elements.length; i < il; ++i) {
51 if ((useDf) ? n : (n && !d)) {
52 n = encodeURIComponent(n) + '=';
53 v = encodeURIComponent(e.value);
56 // Safari, Opera, FF all default options.value from .text if
57 // value attribute not specified in markup
59 if (e.selectedIndex > -1) {
60 o = e.options[e.selectedIndex];
61 data[item++] = n + eUC((o.attributes.value && o.attributes.value.specified) ? o.value : o.text);
64 case 'select-multiple':
65 if (e.selectedIndex > -1) {
66 for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
69 data[item++] = n + eUC((o.attributes.value && o.attributes.value.specified) ? o.value : o.text);
81 // stub case as XMLHttpRequest will only send the file path as a string.
83 // stub case for fieldset element which returns undefined.
85 // stub case for input type reset button.
87 // stub case for input type button elements.
95 return s ? data.join('&') + "&" + s : data.join('&');
101 }, '3.0.0' ,{requires:['io-base','node-base','node-style']});