Closed AleenWael closed 3 years ago
The action/function is never called on pressing a RadioButton i.e onPress: toggleRadio
- toggleRadio(id: string) is never invoked. Why? What is the behaviour of onPress()
onPress function is invoked and updated state of radio buttons is passed to caller function. Please find the link to working example in https://github.com/ThakurBallary/react-native-radio-buttons-group/issues/25#issuecomment-846493544
there are two onPress, one for RadioGroup and another for RadioButton. I am speaking about one for RadioButton. It's never invoked. Can you give sample usage in the example shared?
RadioButton onPress is invoked on a touch of the item. I'm not sure what made you think that RadioButton onPress is not invoked. Can you please share the code snippet?
there are two onPress, one for RadioGroup and another for RadioButton. I am speaking about one for RadioButton. It's never invoked. Can you give sample usage in the example shared?
I suffer from the same problem, when using the RadioButton's OnPress(), it is never invoked.
An example:
{ id: '1', label: 'Test', value: '', borderColor: theme.colors.primary, color: theme.colors.primary, onPress: () => { console.log('Press?') }
@ThakurBallary your example uses the onPress passed to RadioGroup. We are referring to the one passed to a single RadioButton. Can you kindly adjust your example with that uses case to show how to use the RadioButtons onPress(), or otherwise let us know if is faulty, so we may know how to help if possible.
@RowlandOti @victor47n Thanks for writing. Sorry, it took some time for me to understand. @victor47n example has helped me to understand the issue. Release v2.2.7 with the fix. Working example on Snack
Thanks for the quick fix, I can confirm this works now.
@ThakurBallary Thanks for the quick fix!
Para pegar o value fiz assim:
onPress={(selectedId) => {
const selectedItem = radioButtons.find(item => item.id === selectedId);
console.log('selectedItem', selectedItem);
if (selectedItem) {
setSelectedId(selectedItem.id);
onChange(selectedItem.value);
}
}}
There are multiple ways to get the selected value. One of the way is, using find method on array.
arr.find(e => e.selected)?.value