diff --git a/CHANGELOG b/CHANGELOG index dd8e961..52b0636 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/src/form.js b/src/form.js index 13b7929..54a271d 100644 --- a/src/form.js +++ b/src/form.js @@ -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); } diff --git a/test/unit/form.html b/test/unit/form.html index 01be2fc..e58afca 100644 --- a/test/unit/form.html +++ b/test/unit/form.html @@ -66,6 +66,14 @@ +
+ + + + + +
+
@@ -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) {