Skip to content

DataViews: Array fields with enableGlobalSearch throw "input.trim is not a function" error #70782

@dsas

Description

@dsas

Description

When an array field (like categories: ['Space', 'NASA']) from the test fixtures has enableGlobalSearch: true, the global search functionality throws a TypeError because the normalizeSearchInput function expects a string but receives an array.

Expected behavior: Global search should work with array fields, matching search terms against array values (e.g., searching "NASA" should match items with "NASA" in their categories array).

Current behavior: Throws TypeError: input.trim is not a function when attempting to search with array fields enabled for global search.

Step-by-step reproduction instructions

  1. Create a dataview with array field data:
  const data = [
    { title: 'Apollo', categories: ['Space', 'NASA'] },
    { title: 'NASA', categories: ['NASA'] }
  ];
  1. Configure fields with enableGlobalSearch: true on the array field:
  const fields = [
    { id: 'title', enableGlobalSearch: true },
    { id: 'categories', type: 'array', enableGlobalSearch: true }
  ];
  1. Perform a global search:
  filterSortAndPaginate(data, { search: 'NASA' }, fields);
  1. Result: TypeError: input.trim is not a function is thrown

Screenshots, screen recording, code snippet

this patch shows the current behaviour and what should happen (skipped)

array-field-search-bug-test.patch

Environment info

GB trunk: c2842ff

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

Labels

[Package] DataViews/packages/dataviews[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions