diff --git a/lib/forms.js b/lib/forms.js index 67bfec7..e3dab1a 100644 --- a/lib/forms.js +++ b/lib/forms.js @@ -29,7 +29,9 @@ exports.create = function (fields) { b.toHTML = f.toHTML; b.fields = {}; Object.keys(f.fields).forEach(function (k) { - b.fields[k] = f.fields[k].bind(data[k]); + if (data[k] != null) { + b.fields[k] = f.fields[k].bind(data[k]); + } }); b.data = Object.keys(b.fields).reduce(function (a, k) { a[k] = b.fields[k].data; diff --git a/test/test-form.js b/test/test-form.js index 768ed37..443d546 100644 --- a/test/test-form.js +++ b/test/test-form.js @@ -224,6 +224,16 @@ test('handle empty object', function (t) { t.end(); }); +test('handle missing multi-form section', function (t) { + t.plan(1); + var f = forms.create({ + section1: {field1: forms.fields.string()}, + section2: {field1: forms.fields.string()} + }); + f.bind({section1: {field1: "string"}}); + t.ok(true, 'Form handled missing section ok.'); +}); + test('handle error', function (t) { t.plan(5); var f = forms.create({field1: forms.fields.string()});