Netlify-cms: Fields default to null value

Created on 2 Jan 2018  路  6Comments  路  Source: netlify/netlify-cms

- Do you want to request a feature or report a bug?

enhancement

- What is the current behavior?

Fields default to a null value, which just causes weird things to happen sometimes.

- If the current behavior is a bug, please provide the steps to reproduce.

See #895 for one manifestation of this bug. Note: that issue involves default values of widgets inside of Markdown editor shortcodes, but this bug is not limited to that context, and is not known to be specific to Markdown editor shortcodes at all.

- What is the expected behavior?

Default values should probably be provided by each widget, with the fallback remaining as null. For example, the string widget and markdown widget should always default to a blank string value.

- Please mention your CMS, node.js, and operating system version.

CMS 1.0.3

ueditor claimed beginner enhancement

All 6 comments

This could also be fixed along with https://github.com/netlify/netlify-cms/issues/725.

I would be interested in working on this issue if it is still free.

@MichaelRomani That would be great. There was some related discussion in https://github.com/netlify/netlify-cms/issues/725 as well.

@MichaelRomani I'm going to post your last comment from Gitter here, easier to track things:

Again, regarding #977, I see the input value is set in Shortcode.js with its value being extracting from nodes passed into the rendNode function which is called within Slate, a slate-react component. I also see that the 'action' changeDraftField function, which I believe ultimately sets the displayed markdown value , is passed to Visual Editor and called within its handleDocumentChange function. The handleDocumentChange function takes an argument that was passed to it by Visual Editor's handlChange which received the argument from within Slate as well.

Is this the right direction? At this point I'm looking into slate-react to see if I can find where these functions are being called and what arguments are being passed in. I see a value is also being passed as 'value' to Slate and will try to find out if it is this value is ultimately being used as the argument in these functions. Thanks!

And @tech4him1's response:

@MichaelRomani I don't believe #977 is talking about the shortcodes or markdownPlugins at all. It's talking about the default value for each widget (like the date or select widgets) and how to set that. Right now, we are doing it like this:
https://github.com/netlify/netlify-cms/blob/master/src/components/EditorWidgets/Date/DateControl.js#L24-L30
There needs to be a way to set the default directly in the Redux store, instead of having to call onChange to set it.

ping @erquhart

@MichaelRomani let me know if that doesn't make sense

Finally, my thoughts:

The confusion here is my fault - I linked #895 in the summary without providing context (now updated). That issue is about "editor components", a.k.a. Shortcodes, breaking when empty, but the underlying issue has nothing to do with shortcodes - the fields in those shortcodes are regular widgets, the same as those used outside of shortcodes. #895 is just one manifestation of the issue described in the summary.

@MichaelRomani this means that this issue is way less complicated than it probably seemed - you don't have to muck around with that crazy markdown widget at all (I hope). We just need the field value to be the right type, e.g. an empty String widget's value should be an empty string, not null.

Does that make sense?

Shawn, thank you for the clarification. I was reading into the connected issue(s) too much and not focusing on the main issue described. So to clarify, the field values for all of the widgets within Editor Widgets, if the value is null, the value should be set to the correct 'empty' type, ie. empty object, empty string, etc... ?

Also, should I be updating the redux store's image, data, body, title values on load to be empty strings (aside from date which is already being set on load)?

Thanks.

Closed by #1126.

Was this page helpful?
0 / 5 - 0 ratings