From 6534abad36dafd74ed97a889bddc567e94d83f23 Mon Sep 17 00:00:00 2001 From: Luis Correia Date: Tue, 9 Apr 2019 14:58:16 -0700 Subject: [PATCH 1/2] Avoid crashing on null/undefined values for Toggle's on prop --- packages/netlify-cms-ui-default/src/Toggle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/netlify-cms-ui-default/src/Toggle.js b/packages/netlify-cms-ui-default/src/Toggle.js index 1d17de60fa80..1673a8bb3db5 100644 --- a/packages/netlify-cms-ui-default/src/Toggle.js +++ b/packages/netlify-cms-ui-default/src/Toggle.js @@ -64,7 +64,7 @@ const Toggle = ({ className={className} {...getTogglerProps({ role: 'switch', - 'aria-checked': on.toString(), + 'aria-checked': on ? 'true' : 'false', 'aria-expanded': null, })} > From 6a1cbc634bd26626e1362694d80da00f116f4763 Mon Sep 17 00:00:00 2001 From: Luis Correia Date: Tue, 9 Apr 2019 16:03:38 -0700 Subject: [PATCH 2/2] Fallback to widget's component defaultProps for defaultValue on store --- .../netlify-cms-core/src/actions/entries.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/netlify-cms-core/src/actions/entries.js b/packages/netlify-cms-core/src/actions/entries.js index 9529ce25786e..bd323eaa8a43 100644 --- a/packages/netlify-cms-core/src/actions/entries.js +++ b/packages/netlify-cms-core/src/actions/entries.js @@ -9,6 +9,7 @@ import { selectCollectionEntriesCursor } from 'Reducers/cursors'; import { Cursor } from 'netlify-cms-lib-util'; import { createEntry } from 'ValueObjects/Entry'; import ValidationErrorTypes from 'Constants/validationErrorTypes'; +import { resolveWidget } from 'Lib/registry'; const { notifSend } = notifActions; @@ -427,7 +428,23 @@ function createEmptyDraftData(fields) { 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); + const getDefaultValueFromWidget = componentName => { + const widgetComponent = resolveWidget(componentName); + + if (!widgetComponent) { + return null; + } + + const { + control: { + defaultProps: { value: widgetComponentDefaultValue } = { + value: null, + }, + }, + } = widgetComponent; + return widgetComponentDefaultValue; + }; + const defaultValue = item.get('default', getDefaultValueFromWidget(item.get('widget'))); if (List.isList(subfields)) { acc[name] = list ? [createEmptyDraftData(subfields)] : createEmptyDraftData(subfields); @@ -439,9 +456,7 @@ function createEmptyDraftData(fields) { return acc; } - if (defaultValue !== null) { - acc[name] = defaultValue; - } + acc[name] = defaultValue; return acc; }, {});