Fix an issue with serializing empty array inputs, fixes #7516, merges [6309] and [6312] from from branch
This commit is contained in:
parent
aa7ba0d4ff
commit
ebd3351b20
|
@ -1,6 +1,8 @@
|
|||
*SVN*
|
||||
|
||||
* Add optional third parameter "camlized" to Element.setStyle, for optimized performance if style names are known to be camelCased. [Thomas Fuchs]
|
||||
* Fix an issue with serializing empty array inputs, fixes #7516. [stakadush, Mislav Marohnić]
|
||||
|
||||
* Add optional third parameter "camelized" to Element.setStyle, for optimized performance if style names are known to be camelCased. [Thomas Fuchs]
|
||||
|
||||
* Fix a bug in the simulated hasAttribute for IE due to getAttributeNode sometimes returning null. [sam]
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ var Form = {
|
|||
var data = elements.inject({}, function(result, element) {
|
||||
if (!element.disabled && element.name) {
|
||||
var key = element.name, value = $(element).getValue();
|
||||
if (value != undefined) {
|
||||
if (result[key]) {
|
||||
if (value != null) {
|
||||
if (key in result) {
|
||||
if (result[key].constructor != Array) result[key] = [result[key]];
|
||||
result[key].push(value);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,14 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<form id="form_array">
|
||||
<input type="text" name="twin" value="" />
|
||||
<input type="text" name="twin" value="siamese" />
|
||||
<!-- Rails checkbox hack with hidden input: -->
|
||||
<input type="checkbox" id="checkbox_hack" name="checky" value="1" />
|
||||
<input name="checky" type="hidden" value="0" />
|
||||
</form>
|
||||
|
||||
<form id="form_getelements">
|
||||
<select id="tf_selectOne" name="tf_selectOne"><option></option><option>1</option></select>
|
||||
<textarea id="tf_textarea" name="tf_textarea"></textarea>
|
||||
|
@ -273,8 +281,19 @@
|
|||
$('input_enabled').enable();
|
||||
assertEqual('val1=4', Form.serialize('form'));
|
||||
|
||||
// Checks that select-related serializations work just fine
|
||||
assertEqual('vu=1&vm%5B%5D=1&vm%5B%5D=3&nvu=One&nvm%5B%5D=One&nvm%5B%5D=Three&evu=&evm%5B%5D=&evm%5B%5D=Three', Form.serialize('form_selects'));
|
||||
// Checks that select-related serializations work just fine
|
||||
assertEqual('vu=1&vm%5B%5D=1&vm%5B%5D=3&nvu=One&nvm%5B%5D=One'+
|
||||
'&nvm%5B%5D=Three&evu=&evm%5B%5D=&evm%5B%5D=Three',
|
||||
Form.serialize('form_selects'));
|
||||
|
||||
// should not eat empty values for duplicate names
|
||||
$('checkbox_hack').checked = false;
|
||||
var data = Form.serialize('form_array', true);
|
||||
assertEnumEqual(['', 'siamese'], data['twin']);
|
||||
assertEqual('0', data['checky']);
|
||||
|
||||
$('checkbox_hack').checked = true;
|
||||
assertEnumEqual($w('1 0'), Form.serialize('form_array', true)['checky']);
|
||||
}},
|
||||
|
||||
testFormSerializeWorksWithNonFormElements: function() {with(this) {
|
||||
|
|
Loading…
Reference in New Issue