question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to reset all the choices in SelectInput on Change of FormData

See original GitHub issue

What you were expecting: I’m rendering a RefrenceInput inside the FormDataConsumer, If there are any changes in FormData , the
ReferenceInput have to load Options to select , and reset the selected values already.

What happened instead: The ReferenceInput loading options But the previously selected option remain in the list.

Steps to reproduce: Use the RefrenceInput inside the FormDataConsumer

Related code:

<FormDataConsumer>
     {({ formData, ...rest }) =>
         formData ? formData.school_province &&
             <ReferenceInput label="District" source="school_district" reference="options" filter={{ table: 'District_List', filter: ['province_id,=,' + formData.school_province] }}>
                 <SelectInput optionText="district" {...rest} />
             </ReferenceInput>
             : ''
      }
</FormDataConsumer>

Environment

  • React-admin version:2.3.4
  • Last version that did not exhibit the issue (if applicable):
  • React version:16.3.1
  • Browser:Chrome 68.0.3440.106

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
fzaninottocommented, Dec 12, 2018

In fact, After thinking a bit more about it, the problem does not lie with the options, but with the value…

In the example of state/city dropdowns, given that you selected state A and city A1, then if you select state B, the value of city should reset to undefined since A1 isn’t in state B. In that case, react-admin wouldn’t display the previous value in the list.

State  [A] B C D
City [A1] A2 A3 A4

State  A [B] C D
City [ ] B1 B2 B3 B4

Now what’s left to decide if it’s react-admin’s job or not to remove the value if it is not in the list of possible options. By default, it doesn’t make sense (because the list of options is limited, and it can be very resource consuming to make sure that the value is a possible option). But we could make that optional.

I think that it would need to be in react-admin if there were no simple way to do it otherwise. I need to study redux-form deeper to decide.

1reaction
mo-ah-dawoodcommented, Jan 10, 2019

I solved resetting the value using redux-form

  1. import change from redux-form
    • import {change } from 'redux-form'
  2. give my simple form a name
    • <SimpleForm form="myFrm"
  3. i found that FormDataConsumer passes dispatch func. on rest object so i used it
    • onChange={() => rest.dispatch(change("myFrm", "myField", ""))}

here is my code . hope it can help any one image

Read more comments on GitHub >

github_iconTop Results From Across the Web

react admin - Unable to reset all the choices in SelectInput
1 Answer 1 · import change from redux-form. import { change } from redux-form · Give your SimpleForm a name · Move your...
Read more >
selectInput fails to select (always resets) with Shiny > 10.0
The basic problem is that the selectInput drop downs for Dependent Variable and Independent Variables and weight variable reset after each selection.
Read more >
Phoenix.HTML.Form - HexDocs
Generates a reset input to reset all the form fields to their original state. All options are forwarded to the underlying input tag....
Read more >
Input Components - React-admin - Marmelab
React-admin uses react-hook-form to control form inputs. Each input component also accepts all react-hook-form useController hook options.
Read more >
Forms in HTML documents - W3C
Form submission method; Successful controls; Processing form data ... attribute name required for all but submit & reset --> <!ELEMENT INPUT - O...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found