Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceArrayInput with AutocompleteArrayInput clearing previously selected items on search #10272

Open
woutb opened this issue Oct 11, 2024 · 2 comments

Comments

@woutb
Copy link

woutb commented Oct 11, 2024

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

@fzaninotto
Copy link
Member

Why do you override the name prop? Does the bug occur even if you don't override it?

@slax57
Copy link
Contributor

slax57 commented Oct 11, 2024

Also, please provide a reproduction sandbox (codesandbox / stackblitz)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants