-
-
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
Allow empty fields to be removed from frontmatter on update #2017
Comments
I think it would be better if we could infer this from Although, there's some potential to break stuff for people relying on the existence of fields in frontmatter because in the templates they're evaluating against empty strings and not just falsy values (I remember having to do such things in Harp, hence the concern). |
Inferring from |
@erquhart Besides this thing that I found reported on #2067, I also found that if input fields are left untouched (at least) when creating a new entry, these won't be featured in the global state and thus will not be part of the serialized data handed to the backend class for persistence. So, technically, if you create a collection with a non-required field, you can happily create entries for which the field will never be present on the frontmatter. This is not as much a workaround for @richblend as it is a faulty behaviour IMHO so we should also discuss handling this situation. |
@erquhart I'm giving a shot at tackling this as follows:
As to possible "breaking changes", I believe that users relying on the "workaround" mentioned in my last comment would be relying on an implementation detail and thus we should go ahead with launching such a feature as a minor bump (probably with a word of warning on the changelog). Let me know what you think, I'm going to start laying down some ground work. Thanks! |
We definitely need the widget's initial value in the store, agreed. Regarding including/excluding fields in output, I propose that the CMS never evaluate a field's value for "emptiness", and instead always persist values as is. The only exception would be If we then add an Tangentially, I'm now thinking |
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 needs an urgent fix. You can't use Gatsby with Netlify CMS until this issue is resolved. |
Closing in favor of #995. |
Is your feature request related to a problem? Please describe.
When an optional field is left empty, it is not written to frontmatter at all when first published.
If an existing entry is updated, and a field that previously had a value is now empty, it is set as an empty string, instead of being removed completely.
I am seeing this behaviour on image fields. This is a problem for my build (using Gatsby JS), as when it infers its Graphql schema from the frontmatter data, it will incorrectly infer an image field as a string (since it detects the empty quotes), whereas I need it to be completely removed from frontmatter (in this case Graphql will not try to infer its schema from that particular entry).
Describe the solution you'd like
There is at least one existing issue requesting the opposite (#1988 - where updating empty values should default to empty string), so I think this could be an opt-in feature.
I'd like to be able to add an attribute to a widget field config, something like
deleteWhenEmpty: true
, that would completely strip out the frontmatter field if it is empty when published.Describe alternatives you've considered
I have tried to deal with this on the Gatsby side, to remove nodes from Graphql that use empty quotes, but haven't had any luck so far.
Additional context
The text was updated successfully, but these errors were encountered: