-
-
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
Values from string and markdown widgets come out as either empty string or undefined, depending on whether the field has been edited #1449
Comments
Likely related to #1432. |
@tech4him1, that one only affects markdown fields, though? This one can also be reproduced with |
Yes, you are correct. This whole issue (including boolean fields) is related to #977, but that was supposedly fixed. Maybe we need to initialize the Redux store with the defaults as well, not just the widgets. |
So perhaps:
|
This may be cleaner as part of the widget itself, as suggested in #725.
We'll need to decide what the defaults should be for built-in widgets as well. Point number 2 is the only thing really new here, IMO. For example, with a string widget, what should happen:
This may need to be different for optional and required fields -- the main point is that the two questions above are consistent. I hope that makes sense, I'm not trying to argue here. :) |
We need to allow dynamic default values to be set for hidden widgets, where the React component is never loaded, so the separation is going to happen, and doing the same thing two ways will get confusing. Passing the default value to the CMS also gives the core more control over the experience without limiting extension developers. I expect we'll start thinking of a widget as bigger than just a React component as we move into more robust behaviors. I'm even starting to view our tendency to do everything via component methods as an anti-pattern, because it limits our use of that functionality. E.g., only the control component itself can validate widget output because we use a What's new here is having a single set of conditions governing defaults and establishing the following consistent expectations:
|
Hmm your point on what happens after a value is changed and then deleted to an empty string isn't really addressed. Almost feels like we need our own set of "falsey" values for those that you'd just never expect to persist. Like In that case other value types like numbers and objects would be left to the widget developer to ensure a "blank" value ( Thoughts? |
Yes at least one.. in gatsby you define a graphql query from say the source of a yaml file from netlify cms.. but then all of sudden the user deletes a field and the build is broken because gatsby cannot find that field anymore.. |
I'd really love for that to be fixed on the Gatsby side, Netlify CMS isn't the only entry point where that pain is felt. But I'm not 100% against it, it makes sense to provide some way to output an empty string or any other falsey value if the implementor wants. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This can be fixed in Gatsby by explicity defining the schema, as per the documentation. Instead of returning an empty string if a field is edited then deleted (which causes issues for any widgets other than strings), it should just remove the field entirely from the yaml/markdown/json file so that a GraphQL query with explicitly defined schema will return the value as |
@TidyIQ thanks for adding that, much better approach than outputting empty strings. |
Closing in favor of #995. |
- Do you want to request a feature or report a bug?
bug
- What is the current behavior?
String and markdown widgets that are empty produce different data values, depending on whether the field has been edited.
- If the current behavior is a bug, please provide the steps to reproduce.
config.yml
:Observe that the
nonrequiredstring
field isn't in the frontmatter of the resulting markdown file.Observe that frontmatter of the resulting markdown file contains
nonrequiredstringfield: ''
- What is the expected behavior?
That the resulting value is the same in both cases, preferably
undefined
.The issue can also be observed for
string
andmarkdown
widgets showing up in editor components. Also if you open an existing item, remove the text in a field, then Publish.- Please mention your versions where applicable.
Netlify CMS version: 1.9.2
Browser version: Chrome 67.0.3396.87/OSX
Node.JS version: 10.4.1
Operating System: Mac OSX 10.13.5 (High Sierra)
The text was updated successfully, but these errors were encountered: