SelectInput with default value causes Create form reset when switching form tabs
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:
- Create form with couple of tabs containing
SelectInputwith defaultValue set - 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:
- Tab1.title is filled and switched to Tab2 -> form is completely reset
- If Tab1 SelectInput doesn't have defaultValue set, switching to Tab2 reset form only once (?)
- 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
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?
https://github.com/marmelab/react-admin/milestones
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