setValue hook with array data from a checkbox field #11511
Unanswered
tim-cockburn
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I'm having an issue with the react hook form using array data from a collection of checkboxes. basically i want to limit the number of checked boxes but also when a user clicks on the checkboxes parent card component, the box gets checked.
to watch for data changes i am also using the watch api like so...
const toggles = watch('select',[])
my check boxes within the form.....
{ brochures && brochures.map((brochure,index) => {
return (
<div className="col col-6 col-lg-3 p-3 mx-auto" key={brochure.code + index}>
<div className="card p-3 shadow-sm" onClick={()=>setValues( toggles, brochure.code )}>
<input {...register("select",{required:true, maxLength:3})}
className={
form-check-input
}type="checkbox"
value={brochure.code}
id={brochure.code}
disabled={toggles.length >=3 && !toggles.includes(brochure.code) ? true : false}
and the function it hits on the onclick event........
const setValues = (code:string) => {
}
the problem i have is toggles is always a step behind! any ideas???
Beta Was this translation helpful? Give feedback.
All reactions