Skip to content
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

Merged
merged 2 commits into from
Jun 14, 2019
Merged

Conversation

barthc
Copy link
Contributor

@barthc barthc commented Jun 11, 2019

Summary
Currently the createEmptyDraftData function creates an empty array object [{}] and object {}value for list and object widgets without any default value specified in the config file which in turn forces an empty field(s) for the list widget in the editor page. Also for single list 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 a list fields widget. This PR fixes both issues.

@netlify
Copy link

netlify bot commented Jun 11, 2019

Preview proposed changes to netlifycms.org in the link below:

Built with commit d2046ff

https://deploy-preview-2374--netlify-cms-www.netlify.com

@netlify
Copy link

netlify bot commented Jun 11, 2019

Preview proposed changes to the CMS demo site in the link below:

Built with commit d2046ff

https://deploy-preview-2374--cms-demo.netlify.com

Copy link
Contributor

@erquhart erquhart left a 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;
Copy link
Contributor

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.

@erquhart erquhart merged commit 1806a2f into master Jun 14, 2019
@erquhart erquhart deleted the list-widget-fix-default-values branch June 14, 2019 15:46
nathankitchen pushed a commit to nathankitchen/netlify-cms-backend-azure that referenced this pull request Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants