marmelab / aor-dependent-input

A component for displaying input depending on other inputs values in Admin-on-rest
MIT License
60 stars 12 forks source link

Delayed updates on multiple DependentInput depending on SelectInput #12

Open natrim opened 7 years ago

natrim commented 7 years ago

The DependentInput has weird behaviour with defaultValue and SelectInput example below

when you click on the select it does not change value until you click on the same item again if you remove defaultValue's or if you have only one DependentInput it works ok

<SimpleForm>
  <SelectInput source="type" choices={[
    {
      id: 'pc',
      name: 'pc',
    },
    {
      id: 'server',
      name: 'server',
    },
    {
      id: 'gateway',
      name: 'gateway',
    },
    {
      id: 'acnetel',
      name: 'acnetel',
    },
  ]} defaultValue="gateway" />

        <DependentInput resolve={switchType('gateway')}>
          <TextInput source="nat" defaultValue="gateway"  />
        </DependentInput>

        <DependentInput resolve={switchType('pc')}>
          <TextInput source="not" defaultValue="pc" />
        </DependentInput>

        <DependentInput resolve={switchType('server')}>
          <TextInput source="nit" defaultValue="server" />
        </DependentInput>

        <DependentInput resolve={switchType('acnetel')}>
          <TextInput source="net" defaultValue="acntel" />
        </DependentInput>
</SimpleForm>
const switchType = (value) => (values) => {
  return values['type'] === value;
};
dane-du-plessis commented 5 years ago

I have exactly the same issue. Any solutions?

natrim commented 5 years ago

update to new RA where there is not DependentInput

before updating to RA i used modified DependentInput component: gist