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

When 'name' field is null , Autocomplete optionText returns error even though i define inputText

Open utku656 opened this issue 1 year ago • 2 comments

What you were expecting: Screenshot 2024-01-29 at 10 43 04 Screenshot 2024-01-29 at 10 53 25

What happened instead: AuAutocomplete components are directly using react-admin AutocompleteInput component. While we are getting 'name' field null it returns error which you can see above. Even though i define inputText , it still returns the same error. It seems that there is a bug . I tried to give component and function to optionText but all the time i got this error. Also 'code' field is always a string but it still not looking for condition.

Steps to reproduce: try to use null element

Related code:

<AuAutocomplete
                  defaultValue={'-'}
                  emptyValue={'-'}
                  optionText={(choice) => <div>{choice?.name ?? choice?.code}</div>}
                  inputText={(choice) => `${choice?.name} ${choice?.code}`}
                  optionValue="daprAppId"
                  label="Domain"
                  filterToQuery={(q: string) => ({ name: q })}
                />

Other information:

Environment

  • React-admin version: "react-admin": "^4.16.1",
  • Last version that did not exhibit the issue (if applicable):
  • React version: "react": "^18.2.0",
  • Browser:chrome
  • Stack trace (in case of a JS error):

utku656 avatar Jan 29 '24 08:01 utku656

I had a similar problem and could not solve it. I hope the problem will be solved and I will update.

mustafasavul avatar Jan 29 '24 08:01 mustafasavul

I'm sorry, I don't understand your issue. Please rephrase and provide a reproduction based on the simple example Codesandbox (https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple) or on the Storybook for option text element (https://react-admin-storybook.vercel.app/?path=/story/ra-ui-materialui-input-autocompleteinput--option-text-element)

https://github.com/marmelab/react-admin/blob/b6554db5b9e1516bd3b83cf4a26d2d1259c4c25c/packages/ra-ui-materialui/src/input/AutocompleteInput.stories.tsx#L184-L208

fzaninotto avatar Feb 02 '24 21:02 fzaninotto

No news for some time, closing.

fzaninotto avatar May 03 '24 20:05 fzaninotto