I have some checkboxes on each object, and I would like to save the values.
Array of objects
[
{
"title": "Kevin Joe",
"id": "365DmXom2V13xOqagTHczU",
"enabledUnits": ""
},
{
"title": "Kevin 2",
"id": "365DmXom2V13xOqagTHczU",
"enabledUnits": ""
}
]
Some dummy units
const dummyUnits = ["Unit 1", "Unit 2", "Unit 3", "Unit 4", "Unit 5"]
If I click on Unit 1 and Unit 2 For 'Kevin Joe'. This would be the desired result. Added to the object.
[
{
"title": "Kevin Joe",
"id": "365DmXom2V13xOqagTHczU",
"enabledUnits": "Unit 1, Unit 2"
},
{
"title": "Kevin 2",
"id": "365DmXom2V13xOqagTHczU",
"enabledUnits": ""
}
]
Current onChange handler, Is working but is just adding the single value, not multiple.
const createOnChangeHandlerUnits = (floorPlan: FloorPlan, property: 'enabledUnits') => (
e: React.ChangeEvent<HTMLInputElement>
) => {
const {value} = e.target;
setFloorPlans(floorPlans => {
return floorPlans.map(entry => {
if (entry.id === floorPlan.id) {
return {...entry, [property]: value};
}
return entry;
});
});
props.sdk.field.setValue(floorPlans);
};
{dummyUnits.map((unit, i) => {
return (
<CheckboxField id={unit} data-id={i} key={i} value={unit} onChange{(createOnChangeHandlerUnits(floorPlan, 'enabledUnits'))} labelText={unit} />)
})}
