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

List widget: Ability to avoid empty entries #1990

Closed
papandreou opened this issue Jan 3, 2019 · 5 comments
Closed

List widget: Ability to avoid empty entries #1990

papandreou opened this issue Jan 3, 2019 · 5 comments

Comments

@papandreou
Copy link
Contributor

(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

@igufi
Copy link

igufi commented Jan 18, 2019

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

@lmcorreia
Copy link
Contributor

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

@erquhart
Copy link
Contributor

erquhart commented Feb 2, 2019

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

@stale
Copy link

stale bot commented Oct 29, 2019

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.

@erquhart
Copy link
Contributor

erquhart commented Jan 3, 2020

Fixed by #467.

@erquhart erquhart closed this as completed Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants