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 defaultValue not working #7903

Closed
jogibs opened this issue Jun 27, 2022 · 1 comment · Fixed by #7904
Closed

AutocompleteArrayInput defaultValue not working #7903

jogibs opened this issue Jun 27, 2022 · 1 comment · Fixed by #7904
Labels

Comments

@jogibs
Copy link

jogibs commented Jun 27, 2022

I have a custom dashboard page, where I save certain IDs for a resource and save them in local storage, and the code looks something like this:

const MyDialog = () => {
  const [marketIds, setMarketIds] = useLocalStorage<string[]>('marketIds', []);

  return (
    <Dialog>
      <DialogContent>
        <SimpleForm toolbar={false}>
          <ReferenceArrayInput source="markets" reference="Market">
            <AutocompleteArrayInput
              optionText="name"
              onChange={(values) => {
                setMarketIds(values);
              }}
              defaultValue={marketIds}
              fullWidth
            />
          </ReferenceArrayInput>
        </SimpleForm>
      </DialogContent>
    </Dialog>

  )
}

Now, the thing is, this code works fine if the marketIds are entries from one of the first 25 items that it pulls once it's mounted, but if it's not, then the markets input is just blank.

My question is: is there a way to preload the defaultValue entries on mount?

One way I've tried it was with passing the filter={{ ids: marketIds }} to <ReferenceArrayInput />, but this filter is obviously static, so that would affect all subsequent autocomplete queries

I'm using react-admin version 4.1.2

@antoinefricker
Copy link
Contributor

Reproduced and fixed! 👍 @djhi

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

Successfully merging a pull request may close this issue.

2 participants