Disable draft content saving when no fields filled out

Hello,

We have a lot of “draft” entries that are being saved when an editor simply starts to create a new instance of a content item but then changes their mind (or some other similar scenario) without filling in any of the fields. I’m seeing a lot of “draft” items with absolutely no content inside of them.

Is there a way to disable saving the item as a draft if no content is entered in any field, and instead only save the content item as a draft if the editor has at least entered content in a single field?

Thanks,
Diego

Hi @dlorenzo

In order to prevent content lost of the content, auto-save is always enabled.
However, I got your point with empty entries, and probably you can create a custom UI extension to check if all fields are empty and remove or keep entry.
Also, in order to not being lost on Content page with all the entries, you can use Views (left panel) and view only drafts or published entries.

Let me know if that helps.

Hi @andrey - Sorry to bring up an old thread, but I have the same question.

We are using Contentful with Gatsby, and in our preview server we pull from the contentful preview api, but it will inevitably pull in all posts that are in draft mode, including these abandoned posts that are missing required content.

Currently, our only option would be to validate the fields directly from within Gatsby on the React UI layer, to make sure that any of the required fields exist.

Would love to hear any recommendations on how best to solve this.

Hi @cam.s,

Unfortunately, the core of this issue remains the same: there is not a way to directly remove entries that are empty, or simply filter requests to not include them in the response.

The best approach here would be to indeed programmatically do that (e.g. using the Management API to check and remove empty entries), or create a custom UI extension for that purpose, as previously explained by Andrey.

Hi @cam.s,

I’ve actually had the same issue when setting up my Gatsby project and yes, the best way I found was to filter out content (in my case, blog posts) that do not have certain fields populated (in my case, I was looking for posts that have a title value).

So the render code would like something like this:

const allPosts = get(this, 'props.data.allContentfulBlogPost.edges')
const posts = allPosts.filter(post => post.node.title)

I found this filter to be helpful for published content as well since sometimes GraphQL will still find what I like to call “phantom nodes” for entries that I have deleted.

If you want to quickly find unfinished draft content in our web app, you can use our filter pills in the Content section. Look for version is 1 and you will find all the draft entries that were maybe accidentally created and have no content.

version1

Thanks Christina and Gabriel.

I can do this in our gatsby-node file on the initial build, but since I am trying to set up a live preview server using gatsby develop (see here for more details) it will probably only work for the initial build, then I think I will need to check from within the component files to see that all required fields exist, otherwise show some sort of error.

I will keep exploring and see what I can do.

I suppose like Gabriel mentioned, I could also remove any empty entries using the contentful management api. So maybe when the user clicks save to trigger the webhook, it will remove any empty entries before updating the preview server.

1 Like