Unable to reset all the choices in SelectInput on Change of FormData
See original GitHub issueWhat 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:
- Created 5 years ago
- Reactions:4
- Comments:8 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.
I solved resetting the value using redux-form
import {change } from 'redux-form'
<SimpleForm form="myFrm"
onChange={() => rest.dispatch(change("myFrm", "myField", ""))}
here is my code . hope it can help any one