Help to implement radio buttons #377
-
I get the following array from an API: Array exam:
I need to iterate and show the array options as radio buttons. I am iterating over the exam array as follows:
The RadioInput component is this one from the gist below, I copied it in the same way as it is on the website with the documentation: https://gist.github.com/fredarend/b50103f73ba682510bf951326620250e However I have several doubts, the id of the options array is of type number and not string, I do not have items in the options array called value and neither label, only id and option. I am not able to understand what is the correct way to implement this component. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey, @fredarend, the I've cried this example using your code and data, check it out. Hope it helps 💜 |
Beta Was this translation helpful? Give feedback.
-
I ended up managing to solve it as follows: In the RadioButton component I changed the types of data it receives via props to suit what I need:
In htmlFor I transformed the ID which is of type number to String. I also changed other values to suit what I need.
And where I render RadioButton I changed the way to send the props.
|
Beta Was this translation helpful? Give feedback.
-
@jpedroschmitz, in the same form context, with the same options, have you ever implemented something to validate the radio buttons? Generally I use Yup to validate forms, however, as in this context the "name" will always be different from the other, I can't find a way to validate it. We need to validate if any of the options have not been checked. |
Beta Was this translation helpful? Give feedback.
Hey, @fredarend, the
id
was defined as astring
for this example, but you can totally change it for a number or keep both.I've cried this example using your code and data, check it out. Hope it helps 💜