Skip to content

Commit ae215fd

Browse files
committed
Fix #12134. Make .serialize() HTML5-compliant; provide a propHook for shimming.
1 parent a938d7b commit ae215fd

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/serialize.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
var r20 = /%20/g,
22
rbracket = /\[\]$/,
33
rCRLF = /\r?\n/g,
4-
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
5-
rselectTextarea = /^(?:select|textarea)/i;
4+
rcheckTypes = /^(?:checkbox|radio)$/i,
5+
rsubmitterTypes = /^(?:submit|button|image|reset)$/i,
6+
rsubmittable = /^(?:select|textarea|input|keygen)/i;
67

78
jQuery.fn.extend({
89
serialize: function() {
910
return jQuery.param( this.serializeArray() );
1011
},
1112
serializeArray: function() {
1213
return this.map(function(){
13-
return this.elements ? jQuery.makeArray( this.elements ) : this;
14+
// Can add propHook for "elements" to filter or add form elements
15+
var elements = jQuery.prop( this, "elements" );
16+
return elements ? jQuery.makeArray( elements ) : this;
1417
})
1518
.filter(function(){
16-
return this.name && !this.disabled &&
17-
( this.checked || rselectTextarea.test( this.nodeName ) ||
18-
rinput.test( this.type ) );
19+
var type = this.type;
20+
// Use .is(":disabled") so that fieldset[disabled] works
21+
return this.name && !jQuery( this ).is( ":disabled" ) &&
22+
rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
23+
( this.checked || !rcheckTypes.test( type ) );
1924
})
2025
.map(function( i, elem ){
2126
var val = jQuery( this ).val();
@@ -77,13 +82,7 @@ function buildParams( prefix, obj, traditional, add ) {
7782
add( prefix, v );
7883

7984
} else {
80-
// If array item is non-scalar (array or object), encode its
81-
// numeric index to resolve deserialization ambiguity issues.
82-
// Note that rack (as of 1.0.0) can't currently deserialize
83-
// nested arrays properly, and attempting to do so may cause
84-
// a server error. Possible fixes are to modify rack's
85-
// deserialization algorithm or to provide an option or flag
86-
// to force array serialization to be shallow.
85+
// Item is non-scalar (array or object), encode its numeric index.
8786
buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
8887
}
8988
});

0 commit comments

Comments
 (0)