-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): list widget default values #2374
Conversation
Preview proposed changes to netlifycms.org in the link below: Built with commit d2046ff |
Preview proposed changes to the CMS demo site in the link below: Built with commit d2046ff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @barthc, and double thanks for the tests! Just one small change and it's good to merge.
return fields.reduce((acc, item) => { | ||
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 isEmptyDefaultValue = val => [[{}], {}].some(e => isEqual(val, e)); | ||
let subDefaultValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can declare a constant for this in each conditional and avoid mutations.
Summary
Currently the
createEmptyDraftData
function creates an empty array object[{}]
and object{}
value forlist
andobject
widgets without any default value specified in the config file which in turn forces an empty field(s) for thelist
widget in the editor page. Also for singlelist
field
widget with config default key set, the default value generated should come like so['default value']
but outputs something like[{widget_name: 'default value'}]
which should be fine if it's alist
fields
widget. This PR fixes both issues.