payloadcms / payloadcms/payload

'listSearchableFields' does not support searching by select field labels (only values)

Open
#16,349 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: search stale status: needs-triage
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

When using listSearchableFields in a collection, search queries only match the stored value of a select field, not the label.

In cases where label and value differ, users cannot search using the label shown in the UI, which leads to a poor admin experience.

Link to the code that reproduces this issue

https://github.com/MeghaPurohit306/payload

Reproduction Steps
  1. Define a Field with an options array where label and values are different for options (or use the reproduction repo):
  2. `import type { CollectionConfig } from 'payload'

export const UserStatusCollection: CollectionConfig = {
slug: 'user-statuses',
admin: {
useAsTitle: 'status',
listSearchableFields: ['status'],
},
fields: [
{
name: 'status',
type: 'select',
label: 'User Status',
options: [
{ label: 'Active User', value: 'active' },
{ label: 'Expired User', value: 'expired' },
{ label: 'Failed User', value: 'failed' },
{ label: 'Cancelled User', value: 'cancelled' },
],
required: true,
},
],
}
`

  1. Open a document in the admin panel containing this collection, with at least one field
  2. Try to search for "Active User" in search bar
    User will not be able to search by label should pass value thats "active" then only record comes

Expected behavior
User should be able to search by label also as Label is the only user can see.

Actual behavior
When you try to search by Label text no records will be returns though on UI label says "Active User" will not be able to search by this text.

Which area(s) are affected?

plugin: search

Environment Info
"payload": "3.80.0",
"@payloadcms/db-postgres": "3.80.0",
@payloadcms/next": "3.80.0",
"@payloadcms/plugin-cloud-storage": "3.80.0",
"@payloadcms/plugin-nested-docs": "3.80.0",
"@payloadcms/richtext-lexical": "3.80.0",
"@payloadcms/storage-azure": "3.80.0",
"@payloadcms/ui": "3.80.0",
"next": "15.4.11",
"react": "19.2.1",

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction repository and the CollectionConfig using listSearchableFields, then trace the search plugin's handling of select options. Verify the existing value search and add coverage for a label query such as “Active User”; done means both the label and stored value return the matching record.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.