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

New choices of AutocompleteInput not updating when chaging its value

Open ronfogel opened this issue 1 year ago • 1 comments

What you were expecting: When using custom choices, any changes to those choices should be reflected in the options.

What happened instead: It seems that the initial options are being displayed and filtered based on the input text.

Steps to reproduce: I followed the code from the AutocompleteInput documentation (for selecting a foreign key), which updates the choices after fetching new data.

Related code: https://marmelab.com/react-admin/AutocompleteInput.html#selecting-a-foreign-key

import React, { useState } from 'react';
import { AutocompleteInput, useGetList } from 'react-admin';

function LocodeInput(props: any) {
  const [filter, setFilter] = useState({
    q: '',
  });
  const { data, isPending } = useGetList('areas', { filter });

  return (
    <AutocompleteInput
      source="locode"
      label="Locode"
      choices={data}
      isPending={isPending}
      optionText="id"
      optionValue="id"
      onInputChange={(e, value) => {
        setFilter({
          q: value,
        });
      }}
    />
  );
}

export default LocodeInput;

Environment

  • React-admin version: 5.1.3
  • React version: 18.3.1
  • Browser: Chrome

ronfogel avatar Aug 31 '24 17:08 ronfogel

Thanks for reporting this. Please provide a sample application showing the issue by forking the following Stackblitz (https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple).

djhi avatar Sep 02 '24 08:09 djhi