-
-
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
Fields default to Blank String #1126
Conversation
Deploy preview for cms-demo ready! Built with commit e8945fb |
Deploy preview for netlify-cms-www ready! Built with commit e8945fb |
This approach works, but I'd like to see a less involved method for handling defaults since every widget will need to tackle this concern. Right now, we're intentionally setting empty fields to A In doing so, we gain the ability to use React's Thoughts? |
Shawn, just to clarify, you'd like me to set a default for 'value' using defaultProps for each of the editor widgets that has 'value' within its propTypes object. Is this correct? Also, should I default each to an empty string including objects that might ultimately be set to a date / boolean? |
Each value will either be a number, string, boolean, array, object, or an array/object containing these types. Dates, for example, are stringified by their widget on change. Most widgets will use an empty string, with the exception of the boolean, object, and list widget. Perhaps there are others, those are the only ones that come to mind at the moment. I'd expect Boolean to default to false, object to an empty object, and array to an empty array. But again, that's just off the top of my head without testing. |
Thanks, I will make the adjustments and submit early this week! |
I've updated the PR to include 'defaultProps' for values located within the editor widget files. I did not set the default for the date/time as the current set up will only set the current date / time if value is not equal to an empty string. I also updated the createEmptyDraft function to set all values as undefined in place of null. |
src/actions/entries.js
Outdated
@@ -259,7 +259,7 @@ export function createEmptyDraft(collection) { | |||
return (dispatch) => { | |||
const dataFields = {}; | |||
collection.get('fields', List()).forEach((field) => { | |||
dataFields[field.get('name')] = field.get('default', null); | |||
dataFields[field.get('name')] = undefined; |
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.
@MichaelRomani We still want to allow users to manually set a default here, just default it to undefined
instead of null
. The code would be field.get('default')
, just removing null
as the second param like @erquhart mentioned.
@tech4him1 - I've made the adjustment, setting it equal to - field.get('default'). |
Getting close! The ultimate test is creating a new Kitchen Sink entry in the demo - currently failing: https://deploy-preview-1126--cms-demo.netlify.com/#/collections/kitchenSink |
@@ -15,4 +15,8 @@ MarkdownPreview.propTypes = { | |||
value: PropTypes.string, | |||
}; | |||
|
|||
MarkdownPreview.defaultProps = { | |||
value: '', |
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.
Is there a reason we need to set this on the MD preview, and not any of the other previews?
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.
Are you referring to the 'RawEditor' and 'VisualEditor' files?
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.
As far as the kitchen sink goes, I'll take a look this evening or tomorrow afternoon. My apologies, I did not test creating a new sink.
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.
No, I just noticed that you set a default value on the MarkdownPreview as well as the MarkdownControl. Was there a reason?
@MichaelRomani Maybe I missed it, but is there a reason a default isn't set for the ListControl? |
@erquhart Is changing the default from |
It would only be breaking for an installation if someone were intentionally checking for that null value in an external custom widget, in which case, the null value isn't a part of our published API, so it's not technically a breaking change. I also think the likelihood of real world problems resulting is very low, but I'm quite open to being told I'm wrong 😄. |
ListControl - A defaultProp for value was already set in this file as: MarkdownPreview - I removed the defaultProps that had been added to this file. I mistakenly thought it was receiving 'undefined' and needed to be set to ''. Kitchen Sink Error -The error seems to have been coming from ObjectControl. I think the issue is that the defaultProp should have been set to a Map Object as: Let me know if this makes sense and I'll push these changes up to this PR for review. |
Sounds good, push it up! |
@MichaelRomani Great, thanks! |
I've updated the PR. Let me know if changes are needed. |
Any thoughts from anyone about the breaking change concern? cc/ @tech4him1 |
Not that I'm aware of. If bugs emerge we should submit fixes with test coverage, but I haven't seen any issues. |
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.
I think this should be documented at some point for widget authors, but the PR looks good to me!
Summary
Closes issue Fields default to null value #977
Widget values default to blank string when value is null.
Test plan
Values for title, image and body within redux store get set to '' when value is null (date currently being set to current date)
Description for the changelog
Default values directly provided by each widget.