Relation widget filters do not support multiple-value fields
Describe the bug
Relation filters don’t appear to understand multiple values.
If a related collection has a select field with multiple: true:
- name: pets
widget: select
multiple: true
options:
- label: Cats
value: cats
- label: Dogs
value: dogs
- label: Birds
value: birdsand a relation filters that field:
filters:
- field: pets
values:
- cats
- dogsan entry with pets: [cats, birds] isn't matched.
To Reproduce
- Create a collection with a
multiple: trueselect field - Create an entry with more than one selected value
- Create a relation to that collection
- Add a filter for one or more of the possible values
- Note that entries containing those values aren't returned
Expected behavior
If a field contains multiple values, the relation filter should match when any of those values is included in the filter's values.
For example:
entry: [cats, birds]
filter: [cats, dogs]should match because cats is present in both.
Scalar fields should continue to behave exactly as they do now.
Screenshots
Not applicable.
Applicable Versions:
- Decap CMS version: 3.16.3 (unpkg)
- Git provider: GitHub
- OS: Arch
- Browser version: Chrome Version 151.0.7922.71 (Official Build) (x86_64)
- Node.JS version: 26.8.1
CMS configuration
Relevant configuration only:
- name: pets
widget: select
multiple: true
options:
- label: Cats
value: cats
- label: Dogs
value: dogs
- label: Birds
value: birds
# ...etc.
- name: human
widget: relation
collection: example
filters:
- field: pets
values:
- cats
- dogsAdditional context
In RelationControl.js, parseHitOptions currently evaluates the filter with:
filter.values.includes(value)This works when value is scalar, but not when the filtered field contains multiple values.
It seems like a small case of the filter asking, “Is this whole array one of these values?” when it really wants to ask, “Does this array contain one of these values?”
Something like this would be backwards compatible:
Array.isArray(value)
? value.some(item => filter.values.includes(item))
: filter.values.includes(value)Source: decaporg/decap-cms