react-native-simple-radio-button icon indicating copy to clipboard operation
react-native-simple-radio-button copied to clipboard

How can I clean selected choice

Open wyrustaaruz opened this issue 6 years ago • 3 comments

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 avatar Jan 21 '19 12:01 wyrustaaruz

@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');

miteshwo1004 avatar Feb 06 '19 06:02 miteshwo1004

@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

NikhilP97 avatar Feb 09 '19 21:02 NikhilP97

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!

NikhilP97 avatar Feb 11 '19 12:02 NikhilP97