diff --git a/packages/netlify-cms-core/src/actions/entries.js b/packages/netlify-cms-core/src/actions/entries.js index 12c6c835..4a79d4a6 100644 --- a/packages/netlify-cms-core/src/actions/entries.js +++ b/packages/netlify-cms-core/src/actions/entries.js @@ -1,4 +1,4 @@ -import { fromJS, List } from 'immutable'; +import { fromJS, List, Map } from 'immutable'; import { actions as notifActions } from 'redux-notifications'; import { serializeValues } from 'Lib/serializeEntryValues'; import { currentBackend } from 'src/backend'; @@ -360,15 +360,40 @@ export function traverseCollectionCursor(collection, action) { export function createEmptyDraft(collection) { return dispatch => { - const dataFields = {}; - collection.get('fields', List()).forEach(field => { - dataFields[field.get('name')] = field.get('default'); - }); + const dataFields = createEmptyDraftData(collection.get('fields', List())); const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields }); dispatch(emptyDraftCreated(newEntry)); }; } +function createEmptyDraftData(fields) { + return fields.reduce((acc, item) => { + const subfields = item.get('field') || item.get('fields'); + const list = item.get('widget') == 'list'; + const defaultValue = item.get('default'); + + if (List.isList(subfields)) { + acc[item.get('name')] = list + ? [createEmptyDraftData(subfields)] + : createEmptyDraftData(subfields); + return acc; + } + + if (Map.isMap(subfields)) { + acc[item.get('name')] = list + ? [createEmptyDraftData([subfields])] + : createEmptyDraftData([subfields]); + return acc; + } + + if (defaultValue) { + acc[item.get('name')] = defaultValue; + } + + return acc; + }, {}); +} + export function persistEntry(collection) { return (dispatch, getState) => { const state = getState(); diff --git a/packages/netlify-cms-widget-boolean/src/BooleanControl.js b/packages/netlify-cms-widget-boolean/src/BooleanControl.js index 78b7b032..47f2564b 100644 --- a/packages/netlify-cms-widget-boolean/src/BooleanControl.js +++ b/packages/netlify-cms-widget-boolean/src/BooleanControl.js @@ -2,7 +2,6 @@ import PropTypes from 'prop-types'; import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import styled from 'react-emotion'; -import { isBoolean } from 'lodash'; import { Toggle, ToggleBackground, colors } from 'netlify-cms-ui-default'; const BooleanBackground = styled(ToggleBackground)` @@ -13,7 +12,6 @@ export default class BooleanControl extends React.Component { render() { const { value, - field, forID, onChange, classNameWrapper, @@ -24,7 +22,7 @@ export default class BooleanControl extends React.Component {