diff --git a/packages/netlify-cms-core/src/actions/__tests__/entries.spec.js b/packages/netlify-cms-core/src/actions/__tests__/entries.spec.js index c4f22ea376f1..8c6e27f0bf86 100644 --- a/packages/netlify-cms-core/src/actions/__tests__/entries.spec.js +++ b/packages/netlify-cms-core/src/actions/__tests__/entries.spec.js @@ -78,5 +78,18 @@ describe('entries', () => { ]); expect(createEmptyDraftData(fields)).toEqual({}); }); + + it('should not return an empty object for boolean widgets without a default value', () => { + const fields = fromJS([ + { + name: 'post', + widget: 'object', + fields: [{ name: 'title', widget: 'boolean' }], + }, + ]); + expect(createEmptyDraftData(fields)).toEqual({ + post: { title: false }, + }); + }); }); }); diff --git a/packages/netlify-cms-core/src/actions/entries.js b/packages/netlify-cms-core/src/actions/entries.js index 7bfc10d410c3..e211f7b8bb2b 100644 --- a/packages/netlify-cms-core/src/actions/entries.js +++ b/packages/netlify-cms-core/src/actions/entries.js @@ -428,7 +428,11 @@ export function createEmptyDraftData(fields, withNameKey = true) { const subfields = item.get('field') || item.get('fields'); const list = item.get('widget') == 'list'; const name = item.get('name'); - const defaultValue = item.get('default', null); + // A boolean field without a default value defined will initially render + // render as false, but the field will fail the required check. So we are + // assinging false. + const widgetDefaultValue = item.get('widget') == 'boolean' ? false : null; + const defaultValue = item.get('default', widgetDefaultValue); const isEmptyDefaultValue = val => [[{}], {}].some(e => isEqual(val, e)); if (List.isList(subfields)) {