I'm trying to have yup validation on my form.
The form has to have at least one checkbox selected.
The problem that I have multiple checkboxes with dynamic names.
For example, I have an array that looks something like that :
const data = [
{_id: '4d3143f12a54s2', service: 'some service 1'},
{_id: '432gtre52341dd', service: 'some service 2'},
];
inside the React component, I'm looping over him like:
// ....
const SomeComponent = () => {
// ...
return (
<form ......>
{data.map((i) => {
return (
<Checkbox
name={i._id}
label={i.service}
.........
/>
);
})}
</form>
)
}
// ...
I'm trying to know if at least one of the checkboxes is checked. How can I do that?
/* How can I know what is my fields name like that & How can I know at least one of
they are selected?
*/
const someSchema = yup.object().shape({
});