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

Dynamic filter support in ReferenceInput #4507

Closed
tarun-khanna opened this issue Mar 11, 2020 · 0 comments · Fixed by #4508
Closed

Dynamic filter support in ReferenceInput #4507

tarun-khanna opened this issue Mar 11, 2020 · 0 comments · Fixed by #4508
Assignees

Comments

@tarun-khanna
Copy link
Contributor

tarun-khanna commented Mar 11, 2020

What you were expecting:
Changing the filter value in ReferenceInput should make query with new filters.

What happened instead:
Changing filters doesn't work, instead the query uses the same old filter value.

Steps to reproduce:
Change filter of ReferenceInput at runtime by setTimeOut or by another formInput value, and pass the new filter to ReferenceInput.

Related code:
https://codesandbox.io/s/cold-star-f2rfi

Go to comment edit page, and check the console logs printed in dataProvider. The filter for ReferenceInput of Posts was changed after 2 seconds, still the latest query in dataProvider has old filter in params.

const [filter, setFilter] = React.useState({ category: "tech" });
  React.useEffect(() => {
    setTimeout(() => {
      setFilter({ category: "lifestyle" });
    }, 2000);
  }, []);
<ReferenceInput
  source="post_id"
  reference="posts"
  perPage={15}
  sort={{ field: "title", order: "ASC" }}
  fullWidth
  filter={filter}
>
  <AutocompleteInput
    matchSuggestion={(filterValue, suggestion) => true}
    optionText={<OptionRenderer />}
    inputText={inputText}
  />
</ReferenceInput>

Other information:
I have also raised a PR on my approach to solve this issue. Here is the link.
#4508

Environment

  • React-admin version: 3.2.1
  • React version: 16.12.0
  • Browser: Chrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants