react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

ReferenceArrayInput with AutocompleteArrayInput clearing previously selected items on search

Open woutb opened this issue 4 months ago • 2 comments

When I have one or more items selected in the ReferenceArrayInput & I perform a new search in the AutocompleteArrayInput, the selected items are cleared out of the ReferenceArrayInput. Image

Frontend:

  <ReferenceArrayInput
          reference="tags" source="tags" name="name"
                  >
    <AutocompleteArrayInput optionText="name" name="tags"  />
  </ReferenceArrayInput>

Backend response:

[
    {
        "id": "59655158-669b-453b-8290-3a2280ab5856",
        "name": "Tag 1"
    },
    {
        "id": "69655158-e69b-453b-8290-3a2280ab5856",
        "name": "Option 2"
    }
]

Steps to reproduce:

  1. select tag 1
  2. search for 'Option'

Result

  1. The backend loses the first selected item, making the ReferenceArrayInput & the dropdown empty
  2. the search result has no effect and the ReferenceArrayInput gets populated again with the selected items

My first guess is that when you're searching for the second item, the previously selected one isn't in the backend's response. The dropdown sees the new response of the backend, excluding the selected items (because it includes a new filter)

I'd assume that the selected items are cached in the ReferenceArrayInput and not impacted by a new search value.

For now I've made a workaround to include my selected values in my filterToQuery

woutb avatar Oct 11 '24 08:10 woutb