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

Fields default to null value #977

Closed
erquhart opened this issue Jan 2, 2018 · 6 comments
Closed

Fields default to null value #977

erquhart opened this issue Jan 2, 2018 · 6 comments

Comments

@erquhart
Copy link
Contributor

erquhart commented Jan 2, 2018

- 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

@tech4him1
Copy link
Contributor

This could also be fixed along with #725.

@MichaelRomani
Copy link
Contributor

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

@tech4him1
Copy link
Contributor

@MichaelRomani That would be great. There was some related discussion in #725 as well.

@erquhart
Copy link
Contributor Author

erquhart commented Feb 12, 2018

@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?

@MichaelRomani
Copy link
Contributor

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.

@tech4him1
Copy link
Contributor

Closed by #1126.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants