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

Allow optional fields to default to an empty string #1988

Closed
claygiffin opened this issue Jan 2, 2019 · 12 comments
Closed

Allow optional fields to default to an empty string #1988

claygiffin opened this issue Jan 2, 2019 · 12 comments

Comments

@claygiffin
Copy link

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.

@talves
Copy link
Collaborator

talves commented Jan 2, 2019

The big decision is to determine if we make this behavior the same for required: true | false

@papandreou
Copy link
Contributor

Likely related to #1449

If you edit the field with a default value of '', then click publish, I'm fairly sure it does come out as ''?

@talves
Copy link
Collaborator

talves commented Jan 2, 2019

@papandreou related, but there is enough difference that I believe we should keep them separate.

@tomrutgers
Copy link
Contributor

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

@barthc
Copy link
Contributor

barthc commented Jan 4, 2019

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

@talves
Copy link
Collaborator

talves commented Jan 4, 2019

@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. 😜

@talves
Copy link
Collaborator

talves commented Jan 4, 2019

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

@claygiffin
Copy link
Author

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

@papandreou
Copy link
Contributor

Ah, then it might actually be #467

@barthc
Copy link
Contributor

barthc commented Jan 4, 2019

@claygiffin For me, it still works for fields inside list widget. Could you paste the content of your config file?

@claygiffin
Copy link
Author

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

@tomrutgers
Copy link
Contributor

That's weird. Double quotes should work just as well right?

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

No branches or pull requests

5 participants