I am currently creating a react app for animal shelter and i am trying to store an array of value from the check box. i was able to populate the objects on my health schema on the CRUD create of my animal schema. now, i am clueless on how to put the values of checked checkboxes to the form data.
here is the health object on my Animal Schema
healthcare: [
{
type: mongoose.Schema.ObjectId,
ref: 'Health'
}
],
frontend
const NewAnimal = () => {
const [healthcares, setHealthcares] = useState([])
...
const submitHandler = (e) => {
e.preventDefault();
formData.set('healthcares', healthcares);
dispatch(newAnimal(formData))
}
...
<div className="col-6">
<div className="form-group">
<label htmlFor="health_field">Health</label>
<hr/>
{healths.map(health => (
<div key={health._id}>
<input
type="checkbox"
name="checkbox"
id="checkbox"
value={health._id}
onChange={e => setHealthcares.push(e.target.value)}
/>
<label className="form-check-label">{health.name}</label>
</div>
))}
</div>
</div>

