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

Having an issue with the <ReferenceArrayInput> along with the <AutocompleteArrayInput> and optionValue

Open labiang opened this issue 2 years ago • 8 comments

What you were expecting: For the AutocompleteArrayInput to work properly when the optionValue parameter is different from id

What happened instead: It is behaving oddly, if I select a value and then search for a string/character that the first value does not contain, it removes that from the field and marks it as null which then causes the form to submit with an error.

Steps to reproduce: Have a <SimpleForm> along with a <ReferenceArrayInput> which as children has an <AutocompleteArrayInput> with an optionValue parameter different from id.

e.g. (my case)

<ReferenceArrayInput
                                label="Channels"
                                source="config.channel_keys"
                                reference="channels"
                                sort={{ field: 'channel_key', order: 'ASC' }}
                                helperText="Channels to include in the calculations"
                                fullWidth
                                filterToQuery={(searchText) => ({ _q: searchText })}
                            >
                                <AutocompleteArrayInput optionValue="channel_key" optionText="channel_key" />
</ReferenceArrayInput>

Other information: Example of the JS error when that behavior happens: image

Environment

  • React-admin version: 3.19.11
  • Last version that did not exhibit the issue (if applicable):
  • React version: 17.0.2
  • Browser: Brave (chromium engine)
  • Stack trace (in case of a JS error):

labiang avatar Nov 09 '22 07:11 labiang

@WiXSL is this fixed in v4?

geobde avatar Feb 20 '23 23:02 geobde

@geobde The bug report is for v3. There is no reason to believe it doesn't work in v4. If you found a bug, please provide a reproduction.

fzaninotto avatar Feb 21 '23 07:02 fzaninotto

i also getting the same bug @labiang did solve it?

tauqeer-trailfive avatar Aug 23 '23 07:08 tauqeer-trailfive

@fzaninotto

tauqeer-trailfive avatar Aug 23 '23 07:08 tauqeer-trailfive

@tauqeer-trailfive if you want us to take a look at it, p lease provide a reproduction.

fzaninotto avatar Aug 23 '23 07:08 fzaninotto

@fzaninotto you can check it your own

 <ArrayInput
            source="musicalInstruments"
            label="Musical Instruments (Search by name)"
          >
            <SimpleFormIterator
              disableReordering={true}
              fullWidth
              addButton={
                <IconButton title="Add Instrument">
                  <AddIcon color="success" />
                </IconButton>
              }
              removeButton={
                <IconButton title="Remove Instrument">
                  <MinusIcon color="secondary" />
                </IconButton>
              }
              disableClear
            >
              <ReferenceInput
                label="musicalInstruments"
                source="id"
                reference="musicalInstruments"
              >
                <AutocompleteInput
                  optionText={(choice) =>
                    `${choice.name}  /  ${choice.rank}  /  (${choice.id})`
                  }
                  optionValue="id"
                  label="Name / Rank / id"
                  fullWidth
                />
              </ReferenceInput>
            </SimpleFormIterator>
          </ArrayInput>

optionValue should accept other field name rather id of chamge the field name to others then it take null value to dataProvider.

Why it takes id only as a value it should be dynamic

tauqeer-trailfive avatar Aug 23 '23 08:08 tauqeer-trailfive

i just clone the repo and use demo

tauqeer-trailfive avatar Aug 23 '23 08:08 tauqeer-trailfive

@tauqeer-trailfive This isn't clear enough, please provide a link to a StackBlitz based on https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple that reproduces your problem.

fzaninotto avatar Aug 23 '23 08:08 fzaninotto

With the release of react-admin v5, react-admin v3 has reached its end of life. We won't fix bugs or make any new release on the 3.x branch. We recommend that you switch to a more recent version of react-admin.

So I'm closing this issue as we won't fix it.

fzaninotto avatar Jul 02 '24 08:07 fzaninotto