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 form input prevents whitespace and commas #4646

Open
regisphilibert opened this issue Nov 27, 2020 · 8 comments
Open

List widget form input prevents whitespace and commas #4646

regisphilibert opened this issue Nov 27, 2020 · 8 comments
Labels
area: extensions/widgets good first issue type: bug code to address defects in shipped code

Comments

@regisphilibert
Copy link

Describe the bug
When trying to write in list widget input field a comma separated list, it is impossible to add whitespaces or comma.
This was introduced with v2.10.65

To Reproduce

  1. Add a list widget to any collection fields through config
- name: tags
  label: Tags
  widget: list
  1. Go to CMS dashboard and try and edit the field (using whitespace, commas, tabs etc...)

Expected behavior
The user should be able to write in commas and whitespace in the form field.

Applicable Versions:

  • Netlify CMS version: 2.10.65 and above
  • Git provider: GitBhug
  • OS: MacOS Catalina 10.15.7
  • Browser version: Chrome Version 86.0.4240.198

CMS configuration
https://tnd-modules.netlify.app/cms/config.html

@regisphilibert regisphilibert added the type: bug code to address defects in shipped code label Nov 27, 2020
@kalebheitzman
Copy link

I have this same issue

@gavgrego
Copy link

gavgrego commented Dec 6, 2020

I also have this issue, spaces should be allowed as characters inside individual tags.

@peruvianidol
Copy link

I'm not a JS expert but this line seems to be trimming whitespace whenever the content of the field changes:

https://github.com/netlify/netlify-cms/blob/141a2eba565a6fd8b6d8be200481344550501974/packages/netlify-cms-widget-list/src/ListControl.js#L157

@SeanMcP
Copy link

SeanMcP commented Mar 26, 2021

I agree that the list widget should allow spaces.

For a quick fix, you can add a custom widget with the desired behavior. This works for me (and is only slightly modified from the example):

<script>
      var ArrayControl = createClass({
        handleChange: function (e) {
          const separator = this.props.field.get("separator", ", ");
          this.props.onChange(e.target.value.split(separator));
        },

        render: function () {
          const separator = this.props.field.get("separator", ", ");
          var value = this.props.value;
          return h("input", {
            id: this.props.forID,
            className: this.props.classNameWrapper,
            type: "text",
            value: value ? value.join(separator) : "",
            onChange: this.handleChange,
          });
        },
      });

      var ArrayPreview = createClass({
        render: function () {
          return h(
            "ul",
            {},
            this.props.value.map(function (val, index) {
              return h("li", { key: index }, val);
            })
          );
        },
      });

      var schema = {
        properties: {
          separator: { type: "string" },
        },
      };

      CMS.registerWidget("array", ArrayControl, ArrayPreview, schema);
</script>

Then use the array widget in your config.yml:

- label: "Tags"
  name: "tags"
  widget: "array"

Here's what it looks like in the editor:
image of custom array widget (which looks like all the other widgets)

And then the final data in markdown:

tags:
  - Test One
  - Test Two

@robert-duplock-adg
Copy link

As this comes up as the first result on google, I thought I'd suggest another workaround: create a list of string widgets.
@file /admin/config.yml

fields:
  - { label: "Tags", name: "tags", widget: "list", summary: "{{fields.tag}}", field: { label: "Tag", name: "tag", widget: "string" }}

@zeroLR
Copy link

zeroLR commented Sep 4, 2022

As this comes up as the first result on google, I thought I'd suggest another workaround: create a list of string widgets. @file /admin/config.yml

fields:
  - { label: "Tags", name: "tags", widget: "list", summary: "{{fields.tag}}", field: { label: "Tag", name: "tag", widget: "string" }}

This solution helped me to resolve this issue ! Thanks !
More informations are on the official documents : https://www.netlifycms.org/docs/configuration-options/#summary

@adriandpdev
Copy link

adriandpdev commented Apr 22, 2024

important to fix this

duplicate with #7167

@Juniors017
Copy link

it’s a regression, it used to work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: extensions/widgets good first issue type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

10 participants