react-native-simple-radio-button
react-native-simple-radio-button copied to clipboard
How can I clean selected choice
Hello Friend.
In this link there is an example of your project. https://snack.expo.io/@wyrustaaruz/simple-radio-button-cleaner-problem
I want to clean my choice with cleaner button. Changer button is working well with 0...999 or more index number but not working -1 like initial value.
how can I clean my choice?
@wyrustaaruz
I solved it...i think this Helps you...
Replace Function in given location of file.
node_modules/react-native-simple-radio-button/lib/SimpleRadioButton.js
updateIsActiveIndex(index,type) { if(type === "change"){ this.setState({ is_active_index: index }); this.props.onPress(this.props.radio_props[index], index) }else if(type === "clean"){ this.setState({ is_active_index: index }); }else { this.setState({ is_active_index: index }); this.props.onPress(this.props.radio_props[index], index) } }
after that restart your npm start
if you want change selection this.refs.radioForm.updateIsActiveIndex('3','change');
if you want clean selection this.refs.radioForm.updateIsActiveIndex('-1','clean');
@wyrustaaruz
I solved it...i think this Helps you...
Replace Function in given location of file.
node_modules/react-native-simple-radio-button/lib/SimpleRadioButton.js
updateIsActiveIndex(index,type) { if(type === "change"){ this.setState({ is_active_index: index }); this.props.onPress(this.props.radio_props[index], index) }else if(type === "clean"){ this.setState({ is_active_index: index }); }else { this.setState({ is_active_index: index }); this.props.onPress(this.props.radio_props[index], index) } }
after that restart your npm start
if you want change selection this.refs.radioForm.updateIsActiveIndex('3','change');
if you want clean selection this.refs.radioForm.updateIsActiveIndex('-1','clean');
Its throwing an Error: cannot read property 'updateIsActiveIndex' of undefined. Can you please help
I solved it !!!!!!!!!!!!!!!!!!!!!! all you need to do is add a ref attribute in the RadioForm Tag and then call the updateIsActiveIndex(-1) anywhere in your code. This example should explain it better.
render() { return ( <RadioForm ref = {ref => this.radioFormClear = ref} // !! This is the main prop that needs to be there radio_props={this.state.radio_props} initial={-1} // set this so that your inital radioForm is not selcted animation={true} onPress={(value) => {this.onSelect(value)}} /> ) }
Now anywhere in your code ... myDesiredFunction() { this.radioFormClear.updateIsActiveIndex(-1); // just pass -1 and your radio button should clear }
PS: I got this solution partly from @wyrustaaruz, although I couldn't understand what ref was. Also you don't need to change the updateIsActiveIndex( ) function as @wyrustaaruz mentioned. Passing -1 to the original code works. This is my first time contributing to an Issue so hope this helps someone!