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

SelectInput with default value causes Create form reset when switching form tabs

Open zavadpe opened this issue 8 years ago • 9 comments

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

zavadpe avatar Jul 04 '18 13:07 zavadpe

Yes, I got the same problem

aksaha2311 avatar Jul 05 '18 16:07 aksaha2311

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

djhi avatar Jul 05 '18 17:07 djhi

When 2.1.2 will release?

ashim-kr-saha avatar Jul 05 '18 17:07 ashim-kr-saha

https://github.com/marmelab/react-admin/milestones

djhi avatar Jul 05 '18 18:07 djhi

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

djhi avatar Jul 05 '18 18:07 djhi

@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 avatar Jul 25 '18 11:07 zavadpe

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

djhi avatar Jul 25 '18 12:07 djhi

Nevermind, I just reproduced it

djhi avatar Jul 25 '18 12:07 djhi

Fixed by #2082

djhi avatar Aug 01 '18 07:08 djhi