Skip to content

Commit

Permalink
Merge pull request #163 from tmpduarte/fix-serialization
Browse files Browse the repository at this point in the history
Fixes issue #162 - iron-form element does not serialise all duplicates if the first one has value equal to empty string
  • Loading branch information
notwaldorf authored May 25, 2017
2 parents a36defe + 4b30a7a commit ee811a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion iron-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
function addSerializedElement(name, value) {
// If the name doesn't exist, add it. Otherwise, serialize it to
// an array,
if (!json[name]) {
if (json[name] === undefined) {

This comment has been minimized.

Copy link
@tjb1982

tjb1982 May 25, 2017

probably should've been if (typeof json[name] === "undefined") ... as undefined is just a symbol that can be overwritten.

This comment has been minimized.

Copy link
@notwaldorf

notwaldorf May 25, 2017

Author Contributor

if somebody overwrites undefined they deserve everything to be broken :)

json[name] = value;
} else {
if (!Array.isArray(json[name])) {
Expand Down
9 changes: 7 additions & 2 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<form is="iron-form">
<input name="foo" value="bar">
<input name="foo" value="barbar">
<input name="empty" value="">
<input name="empty" value="">
<simple-element name="zig" value="zig"></simple-element>
<simple-element name="zig" value="zag"></simple-element>
<simple-element name="zig" value="zug"></simple-element>
Expand Down Expand Up @@ -375,13 +377,16 @@
f = fixture('Dupes');

assert.equal(f._customElements.length, 3);
assert.equal(f.elements.length, 2);
assert.equal(f.elements.length, 4);

var json = f.serialize();
assert.equal(Object.keys(json).length, 2);
assert.equal(Object.keys(json).length, 3);
assert.equal(json['foo'].length, 2);
assert.equal(json['foo'][0], 'bar');
assert.equal(json['foo'][1], 'barbar');
assert.equal(json['empty'].length, 2);
assert.equal(json['empty'][0], '');
assert.equal(json['empty'][1], '');
assert.equal(json['zig'].length, 3);
assert.equal(json['zig'][0], 'zig');
assert.equal(json['zig'][1], 'zag');
Expand Down

0 comments on commit ee811a7

Please sign in to comment.