Skip to content

Select field returns [null] in CP entries listing when option labels are omitted #14377

@dadaxr

Description

@dadaxr

Bug description

When a Statamic select field is shown as a column in the Control Panel entries listing, the AJAX response may return [null] instead of the stored value if the field options are defined with explicit key values and null labels.
The entry data is correctly stored and the field is correctly populated in the entry itself. The issue only affects the serialized value returned for the collection listing endpoint in the Control Panel.
This seems to happen because the listing uses preProcessIndex(), which resolves the display label from the configured options. If the matched option exists but its label is null, the returned value becomes null instead of falling back to the option key / stored value.
This looks like an edge case in the CP index serialization for select fields, especially since the label is presented as optional in the fieldtype UI.

If I set a "label" (marked as optional), this works correctly. I think it should display the slug if no label is set instead of null (empty string)

in the entry :
Image

in the collection listing :
Image

In the blueprint :

Image

How to reproduce

  1. Create a collection entry blueprint with a select field.
  2. Configure the field options like this:
handle: univers_type
field:
  type: select
  options:
    -
      key: ingredient
      value: null
    -
      key: ambiance
      value: null
    -
      key: repas
      value: null
  1. Create an entry using that blueprint and save a valid value, for example:
    univers_type: repas
  2. Add this field as a visible column in the Control Panel collection listing.
  3. Open the collection listing in the CP.
  4. Inspect the AJAX response for the entries listing endpoint, for example:
    /cp/collections/{collection}/entries?...&columns=univers_type

Actual result
The response contains:
"univers_type": [null]
even though the stored entry value is repas.
Expected result
The response should fall back to the stored value / option key when the option label is null, for example:
"univers_type": ["repas"]
or another non-null displayable fallback.

Logs

Environment

Environment
Laravel Version: 12.55.1
PHP Version: 8.4.13
Composer Version: 2.8.12
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: UTC
Locale: fr

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mariadb
Logs: stack / daily
Mail: log
Queue: sync
Session: file

Storage
public/storage: NOT LINKED

Statamic
Addons: 2
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 6.7.3 PRO

Statamic Addons
jacksleight/statamic-bard-texstyle: 4.0.0
statamic-rad-pack/runway: 9.1.1

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions