Not able to add to List field with 0 as the first machine name.

Created on 24 January 2024, 5 months ago
Updated 6 June 2024, 18 days ago

Problem/Motivation

I have a List (text) field that I ended up, for migration reasons, using the number 0 as the machine name of the first Allowed value. Migration went great. Now, months later, I need to add another item to the list. So I went to add it and got a "Value field is required." message under the Value field of the 1st Allowed Values enter (See Pics in files)

Steps to reproduce

I tried it in https://simplytest.me/ and got the same problem.

  1. Used Article Content type
  2. Add List (Text) Field
  3. Enter Name of first Value
  4. change machine name to "0" (number 0)
  5. Enter Name of 2nd Value
  6. Enter Machine Name of 2nd to "1"
  7. Save settings
  8. Created test article
  9. Enter values for that field
  10. Go back to add 3rd Value to Content type's field

It won't let you! You get an Error message "Value field is required."

I have a lot of these already done and migrated. If we need to add values down the road, what do we do?

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component
Fieldย  โ†’

Last updated less than a minute ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States tawellman

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @tawellman
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tawellman
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cilefen

    I think this may be previously reported but I havenโ€™t searched in detail.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tawellman

    I have search a bunch. Any suggestion on what to be looking for? Am I using the wrong terminology?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cilefen

    I definitely remember issues concerning 0 values in past. They could be different than this one.

  • I got the same problem. My site actual is a new site set up at core version 10.1.x. At that time the problem wasn't there. It first accrued after updating to 10.2.x. The problem might be related somehow to https://www.drupal.org/project/drupal/issues/3411419 ๐Ÿ› Regression from #2521800: using machine name element for ListStringItem breaks with existing data Fixed ?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Dan_Rogers Driggs, ID

    RE https://www.drupal.org/project/drupal/issues/3411419 ๐Ÿ› Regression from #2521800: using machine name element for ListStringItem breaks with existing data Fixed , this has been committed and seems to be present in release 10.2.3, which I just updated to, but this issue still persists for me.

  • First commit to issue fork.
  • ๐Ÿ‡น๐Ÿ‡ญThailand AlfTheCat

    I tried the patch from MR in #10 on Drupal 10.2.3, but no luck in my case.

    I have a list field with the first option having machine name "0" which I can't update anymore due to this issue.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly Giuseppe87

    Likewise #8 the issue seems to still exists:

    I have a Drupal site with text list fields which have a machine names 0, 1, ...

    On Drupal 10.1.8 they are valid and editable, with 10.2.3 I get ""Value field is required.".

  • ๐Ÿ‡ฎ๐Ÿ‡ชIreland frankdesign

    I'm seeing this issue as well. It only started with Drupal 10.2. Previous versions do not experience this error. It's happening on sites that were upgraded to Drupal 10.2 as well as new installs of Drupal 10.2.

    I'm also experiencing the error if you reuse the list field on another entity type e.g. if you have the field on one paragraph type and then try to reuse the field on another paragraph type. It is worth noting that the field is added to the second paragraph type even though the error is displayed. But you cannot add additional values to the list.

    Note: I have seen this error for both List (text) fields with the machine name of the text string '0' as well as List (integer) fields with the machine name of the number 0.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia noonoos

    10.2.6
    Still have issue.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States potassiumchloride

    I have the same issue. I have a list field and the first option has a machine name "0" and I can't update the field at all. I need to add a default value for the field but because I can't save it without "Value field is required" I can't update the default. This bug renders the field un-editable.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States courtneyjordan Albany, NY

    I'm encountering this issue as well on 10.2.6
    The value field remains disabled, displaying a 0 value.

    The list field i'm working on requires new field options and i'm currently unable to do that and not sure what to do.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Prashant.c Dharamshala

    I am not able to replicate this on 11.x.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States courtneyjordan Albany, NY

    I have an update with a work around. You can ethier remove the field and recreate it adding the new items to your list and keeping the machine names with their boolean values, keep in mind you'd need to do this for every instance you'd need to add a new item. If you have a time constraint and you need to make a quick change without mucking up the code this works.

    -however-

    It's best to recreate the list using a meaningful string of text for the machine name indicating the items action. The you'd never have to worry about the boolean value of 0 impacting future updates to your list.

    These solutions will work but keep in mind if you plan to use boolean values refrain from using 0 as it equals null and that can cause breakage in this case. Hope this helps!

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand John Pitcairn

    While using a value of "0" in a list (text) field is perhaps ill-advised, it should be possible, and it should definitely be possible to use a value of 0 in a list (integer) field. But that produces the same error.

    I guess something is testing whether there's a value using empty() when really it should be calling isset() or a strict equals.

    Re-titling to reflect the more general problem. Fortunately I found this before pushing the new field to production.

Production build 0.69.0 2024