Is your feature request related to a problem? Please describe.
Currently, when a new post is created with optional fields, and those fields are left blank, the outputted .md file will omit those fields instead of returning an empty/null value. This can cause a problem when using GraphQL, which will fail to build when an undefined value is returned. However, it would function just fine with an empty string instead.
Describe the solution you'd like
We should allow empty strings as default values in the config file, and have those empty strings output in the markdown file.
Example:
- {label: "Empty Field", name: "emptyField", widget: "string", default: "", required: false }
would output in blog-post.md as:
emptyField: ""
---
Additional context
This actually seems to be what happens already, but only after a user has filled in the field, saved, and then edited it to be empty again. I would just like to expand this behavior to occur when the post is first created.
The big decision is to determine if we make this behavior the same for required: true | false
Likely related to https://github.com/netlify/netlify-cms/issues/1449
If you edit the field with a default value of '', then click publish, I'm fairly sure it does come out as ''?
@papandreou related, but there is enough difference that I believe we should keep them separate.
I'd prefer to make this functionality available only if a field has required: false. Imho required: true should always prevent the post from being published
@claygiffin May I ask what version of the cms you are on. I believe this issue was fixed in #1859, I tested locally with your sample widget in the config file, created a new post without touching the widget, but I can see emptyField: '' in the frontmatter. Maybe I am misunderstanding the issue here @tomrutgers and @talves can you guys confirm from your end.
@barthc ran it against 2.3.2, but I swore it did not work the other day. Worked!
I was testing so many things. It was my first suggestion and I wonder if I just took his word that it was not working without testing my own case. 馃槣
@claygiffin can you test the case again? Also, Remember that all the existing posts need to have it existing as the default. This will not add it to an existing document if it is missing.
@talves I am running on 2.3.2, and it isn't working for me still.
However, I am also using it within the list module, which could possibly be part of the problem. It looks like it actually is working for me for fields outside the list module.
Ah, then it might actually be https://github.com/netlify/netlify-cms/issues/467
@claygiffin For me, it still works for fields inside list widget. Could you paste the content of your config file?
@barthc @talves You know what, I just realized I was using double quotes instead of single quotes for the default field. Now it works, case closed! Thanks for your help.
That's weird. Double quotes should work just as well right?
Most helpful comment
@papandreou related, but there is enough difference that I believe we should keep them separate.