|
1 | 1 | var r20 = /%20/g, |
2 | 2 | rbracket = /\[\]$/, |
3 | 3 | 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; |
6 | 7 |
|
7 | 8 | jQuery.fn.extend({ |
8 | 9 | serialize: function() { |
9 | 10 | return jQuery.param( this.serializeArray() ); |
10 | 11 | }, |
11 | 12 | serializeArray: function() { |
12 | 13 | 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; |
14 | 17 | }) |
15 | 18 | .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 ) ); |
19 | 24 | }) |
20 | 25 | .map(function( i, elem ){ |
21 | 26 | var val = jQuery( this ).val(); |
@@ -77,13 +82,7 @@ function buildParams( prefix, obj, traditional, add ) { |
77 | 82 | add( prefix, v ); |
78 | 83 |
|
79 | 84 | } 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. |
87 | 86 | buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add ); |
88 | 87 | } |
89 | 88 | }); |
|
0 commit comments