react-native-clean-form
react-native-clean-form copied to clipboard
<Switch value={true} not working
setting the Switch value to true seems not working...
how to initialize the switch value?
@thienpow I haven't used it but looks like you have to set the value prop of Select like <Select value="your value">... You can go through the code at https://github.com/esbenp/react-native-clean-form/blob/master/src/Select.js , look for props and the render function
Switch value is not working even though the code base did inherit all props from the base switch component... It only works by initializing the redux Form data... Which you can't really do some dynamic UI event handling that change the switch on other components interaction...
@thienpow In the example https://github.com/esbenp/react-native-clean-form/blob/master/example/src/Form.js, if I change the value to 'US' or 'DE', then the correct label is pre-selected for me
<FormGroup>
<Select
name="country"
label="Country"
options={countryOptions}
// placeholder="Denmark" -- commented this
value="US" // -- added this, shows "United State"
/>
</FormGroup>
I am not using redux
yeah select is working... i am talking about the <Switch button
Damn.. Sorry! 🤣 Switch works for me.. Maybe post your code?
@thienpow did you add initial data model to state?
I was having the same confusion how to create model driven form.
Followed this https://codesandbox.io/s/MQnD536Km to get the understanding how it gets done in redux-form.
In short you have to connect 'initialValues' to the state and form gets magically filled!
In my case (using https://github.com/reactjs/reselect):
const mapStateToProps = createStructuredSelector({
initialValues: makeSelectCardFieldValues(),//to init values you're looking for
fieldSets: makeSelectFieldsets()// to 'draw' form with fieldsets
});
I can confirm the approach is working fine for <Input />, so one could assume it's also working for <Switch />.