I have an array of objects and I map through them.
{alltasks.map((task) => (
<div key={task.task}>
<input type="checkbox" name="task" id={task.task} value={task} className="hidden peer check" />
<label for={task.task} className="inline-flex items-center justify-between w-full p-5 text-white bg-transparent border-2 border-slate-600 rounded-lg cursor-pointer peer-checked:border-emerald-500 hover:border-emerald-700">
<div>
<img src={task.img} alt="" />
<div className="w-full text-sm mt-2">ID: {task.task}</div>
</div>
</label>
</div>
))}
Each object will now have its own checkbox. I set the checbox's value as the object, so I can use it later.
On submit I want to get all checked checbox's values, so I can store them in an array.
<form className="w-full taskForm" onSubmit={(e) => {
e.preventDefault()
const checkedBoxes = document.querySelectorAll('input[name=task]:checked');
checkedBoxes.forEach((box) => {
console.log(box.value)
})
stateChanger(false)
}}>
But all I get back is [object Object]
not the actual object. How can I get back the actual objects?
Comments
Post a Comment