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

AutocompleteArrayInput: duplicate suggestions #3826

Closed
LoicMahieu opened this issue Oct 16, 2019 · 3 comments
Closed

AutocompleteArrayInput: duplicate suggestions #3826

LoicMahieu opened this issue Oct 16, 2019 · 3 comments
Labels

Comments

@LoicMahieu
Copy link
Contributor

What you were expecting:

Don't have any duplicate suggestions in the AutocompleteArrayInput.

What happened instead:

Using the ReferenceArrayInput:

<ReferenceArrayInput
  source="relatedPosts"
  label="Related posts"
  reference="posts"
>
  <AutocompleteArrayInput optionText="title" fullWidth />
</ReferenceArrayInput>

When editing a record that already have some relatedPosts, when you delete some of them, it produces duplicated suggestions. See the video:
Kapture 2019-10-16 at 10 09 42

Steps to reproduce:

Related code:

Other information:

Environment

  • React-admin version: 3.0.0-beta
  • Last version that did not exhibit the issue (if applicable):
  • React version: 16.9
  • Browser: Chrome
  • Stack trace (in case of a JS error):
@LoicMahieu
Copy link
Contributor Author

It seems to be related to the idsToFetch that are set in the useReferenceArrayInputController.ts#L54-L61.

I tried to remove the newIdsToFetch.length > 0 and it seems to work well but I know if it's a good change:

diff --git a/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts b/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts
index 8aa027fa..0d9007ff 100644
--- a/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts
+++ b/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts
@@ -54,9 +54,7 @@ const useReferenceArrayInputController = ({
     useEffect(() => {
         const newIdsToFetch = difference(input.value, inputValue.current);

-        if (newIdsToFetch.length > 0) {
-            setIdsToFetch(newIdsToFetch);
-        }
+          setIdsToFetch(newIdsToFetch);
         inputValue.current = input.value;
     }, [input.value, setIdsToFetch]);

@LoicMahieu
Copy link
Contributor Author

LoicMahieu commented Oct 16, 2019

I also encountered a another issue but I don't think it is related:
Kapture 2019-10-16 at 14 34 07

Steps:

  • From empty value, add 2 items.
  • Focus out
  • Focus and tap any chars that doesn't match with any item
  • See: some of chip doesn't have text.
  • Focus out: the text of the chip appear again

@djhi djhi added the bug label Oct 16, 2019
@fzaninotto fzaninotto added the v3 label Oct 23, 2019
@fzaninotto
Copy link
Member

Fixed by #3898

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

No branches or pull requests

3 participants