2
YUI 3.10.3 (build 2fb5187)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('io-form', function (Y, NAME) {
11
* Extends IO to enable HTML form data serialization, when specified
12
* in the transaction's configuration object.
18
var eUC = encodeURIComponent;
21
* Enumerate through an HTML form's elements collection
22
* and return a string comprised of key-value pairs.
26
* @param {Node|String} form YUI form node or HTML form id
27
* @param {Object} [options] Configuration options.
28
* @param {Boolean} [options.useDisabled=false] Whether to include disabled fields.
29
* @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs.
32
Y.IO.stringify = function(form, options) {
33
options = options || {};
35
var s = Y.IO.prototype._serialize({
37
useDisabled: options.useDisabled
39
options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);
44
Y.mix(Y.IO.prototype, {
46
* Enumerate through an HTML form's elements collection
47
* and return a string comprised of key-value pairs.
52
* @param {String|Element} c.id YUI form node or HTML form id
53
* @param {Boolean} c.useDisabled `true` to include disabled fields
54
* @param {String} s Key-value data defined in the configuration object.
57
_serialize: function(c, s) {
59
df = c.useDisabled || false,
61
id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
62
e, f, n, v, d, i, il, j, jl, o;
66
c.id.setAttribute('id', id);
69
f = Y.config.doc.getElementById(id);
71
if (!f || !f.elements) {
75
// Iterate over the form elements collection to construct the
77
for (i = 0, il = f.elements.length; i < il; ++i) {
82
if (df ? n : n && !d) {
87
// Safari, Opera, FF all default options.value from .text if
88
// value attribute not specified in markup
90
if (e.selectedIndex > -1) {
91
o = e.options[e.selectedIndex];
92
data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
95
case 'select-multiple':
96
if (e.selectedIndex > -1) {
97
for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
100
data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
108
data[item++] = n + v;
112
// stub case as XMLHttpRequest will only send the file path as a string.
114
// stub case for fieldset element which returns undefined.
116
// stub case for input type reset button.
118
// stub case for input type button elements.
122
data[item++] = n + v;
131
return data.join('&');
136
}, '3.10.3', {"requires": ["io-base", "node-base"]});