I'm attempting to create an 'edit listing' page where someone's submitted information is displayed back. I'm a bit stuck on how to populate checkboxes in a form with a check on the boxes that were selected the first time.
I'm aware that checkboxes look for false/true in order to display a check, but my array of something like: [x,y,z] is displayed as just [true] or [false] which leads to all boxes being checked at once and vice versa when using v-model.
The form
<input
type="checkbox"
id="Set Photographer"
value="Set Photographer"
v-model="returnedListing[0].crew_positions"
/>
<label for="Set Photographer">Set Photographer</label>
<input
type="checkbox"
id="Producer"
value="Producer"
v-model="returnedListing[0].crew_positions"
/>
<label for="Producer">Producer</label>
<input
type="checkbox"
id="Production Designer"
value="Production Designer"
v-model="returnedListing[0].crew_positions"
/>
<label for="Production Designer">Production Designer</label>
returnedListing
const [actors, returnedListing] = await Promise.all([
$axios.$get(`/api/v1/actors/`, {
params: {
user: body
}
}),
$axios.$get(`/api/v1/listings/`, {
params: {
random_public_id: params.id
}
})
]);
return { actors, returnedListing };
Dummy API object
{
"id": 15,
"title": "NUmber 15",
"start_date": "2021-03-04",
"end_date": "2021-02-16",
"location": "The Bronx",
"overview": "sdfds",
"studio": "sdfdsf",
"poster": null,
"crew_positions": "Set Photographer, Producer, Production Designer",
"post_production_positions": "Editing, AD",
"random_public_id": null,
"date_submitted": null,
"user": 1
}
Essentially I'm looking to figure out how to loop through returnedListing[0].crew_positions if it's value is ['Set Photographer', 'Producer'] and have those 2 boxes checked while 'Production Designer' remains unchecked.
crew_positionsinto array by using split method of string then you can use includes method of array to check if value is in array or not.