Netlify-cms: List widget: Ability to avoid empty entries

Created on 3 Jan 2019  路  5Comments  路  Source: netlify/netlify-cms

(First off, I'm not sure if this is a duplicate of #467 or whether it will be addressed by the efforts to solve that. Feel free to just close it if that's the case -- would make me happy 馃槃)

Is your feature request related to a problem? Please describe.

When you have a list widget, it appears there's no way to validate that list entries aren't left blank. That means that if the user clicks the "Add XXX +" button and forgets to fill in the field, it will end up being persisted as either null or '' (depending on whether the field has been edited, probably due to #1449).

This is a problem for "non-technical" people that don't necessarily distinguish between the list entry being empty vs. not being there at all.

Here's an example setup where the problem can be reproduced:

backend:
  name: github
  repo: myrepo
collections:
  -
    name: foos
    label: Foos
    label_singular: Foo
    folder: foos
    create: true
    slug: "{{id}}"
    fields:
      -
        label: Id
        name: id
        widget: string
      -
        label: Title
        name: title
        widget: string
      -
        label: Bars
        label_singular: Bars
        name: bars
        widget: list
        allow_add: true
        field:
          name: id
          label: Bar
          required: true # <- this has no effect
          widget: string

Steps to reproduce:

  1. Create a new Foo
  2. Enter an id and a title
  3. Click the "Add bars +" button
  4. Click "Publish"

Causes something like this to be saved:

+---
id: the id
title: the title
bars:
  - null
---

Describe the solution you'd like
That required: true causes a validation error when publishing with list entry field is left without a value.

Describe alternatives you've considered
Alternatively unfilled list entries could simply be ignored when persisting.

Additional context
screen shot 2019-01-03 at 15 54 51

stale

Most helpful comment

I'm going to test a few possible edge cases such as the list itself having required: true but nested fields having required: false but at the very least the core problem presented here will be solved by the work done for #467

All 5 comments

I came across the same issue when using list widget for setting post categories in Hugo. If a user writes anything to the category field and then deletes it, the post header will still contain the following:

categories: 
  - ''

This causes Hugo to create a post with an empty category tag, that can look something like this:

image

I'm going to test a few possible edge cases such as the list itself having required: true but nested fields having required: false but at the very least the core problem presented here will be solved by the work done for #467

@lmcorreia your comment on #2017 is also relevant here.

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.

Fixed by #467.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ciokan picture ciokan  路  3Comments

ghost picture ghost  路  3Comments

calavera picture calavera  路  3Comments

noelmace picture noelmace  路  3Comments

mikecrittenden picture mikecrittenden  路  3Comments