React-admin: SelectInput with default value causes Create form reset when switching form tabs

Created on 4 Jul 2018  路  9Comments  路  Source: marmelab/react-admin

What you were expecting:
SelectInput works as expected and doesn't cause Create form to reset its values when switching between form tabs.

What happened instead:
SelectInput with defaultValue set causes Create form reset its values when switching between form tabs.

Steps to reproduce:

  1. Create form with couple of tabs containing SelectInput with defaultValue set
  2. Fill up values in one tab and try to switch between tabs

Related code:

<Create {...props}>
    <TabbedForm>
      <FormTab label="Tab 1">
        <TextInput source="title" />
        <SelectInput
          source="type"
          choices={[
            { id: "type1", name: "Type 1" },
            { id: "type2", name: "Type 2" }
          ]}
          defaultValue={"type1"}
        />
      </FormTab>
      <FormTab label="Tab 2">
        <TextInput source="title" />
      </FormTab>
      <FormTab label="Tab 3">
        <SelectInput
          source="category"
          choices={[
            { id: "cat1", name: "Category 1" },
            { id: "cat2", name: "Category 2" }
          ]}
          defaultValue={"cat1"}
        />
      </FormTab>
   </TabbedForm>
</Create>

or check this CodeSandbox.
The following happens in Product Create form:

  1. Tab1.title is filled and switched to Tab2 -> form is completely reset
  2. If Tab1 SelectInput doesn't have defaultValue set, switching to Tab2 reset form only once (?)
  3. If Tab1 and Tab2 SelectInputs both don't have defaultValue, switching tabs works as expected.

CodeSandbox
https://codesandbox.io/s/6n0xlnjzkn

Other information:
I noticed this behaviour in earlier versions (I think it's there from at least 2.0.2).

Environment

  • React-admin version: 2.1.0
  • React version: 16.3.1
  • Browser: any

Most helpful comment

Just checked. I fixed this too with #1997
Will be available in next minor release 2.1.2

All 9 comments

Yes, I got the same problem

Just checked. I fixed this too with #1997
Will be available in next minor release 2.1.2

When 2.1.2 will release?

Btw, thanks @zavadpe for reporting and setting up a codesandbox. It really helps :+1:

@fzaninotto I noticed that fix for this has been reverted in 2.1.4 (seemed to be mostly fixed in 2.1.2 and 2.1.3 although I saw it happen at particular places in my codebase). Any plans to fix it in 2.1.5? This issue should be probably reopened then.. cc: @djhi

@zavadpe I can't reproduce it on 2.1.4. Can you setup a codesandbox showing the issue ?

Nevermind, I just reproduced it

Fixed by #2082

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kopax picture kopax  路  3Comments

rkyrychuk picture rkyrychuk  路  3Comments

Dragomir-Ivanov picture Dragomir-Ivanov  路  3Comments

9747749366 picture 9747749366  路  3Comments

yangjiamu picture yangjiamu  路  3Comments