Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robert Emil Berge's avatar

Checkbox State Does not Reflect v-model State

I have a table of documents and a form where one should be able to choose a selection of these with the help of checkboxes. Some of the documents are already selected, and are in the selected items array ("form.documents"). My problem is that the checkboxes don't reflect the initial selection, but only the ones I make after the page is loaded. If I check the checkbox of a document that should have been selected, I get it duplicated in the selected items array.

I make the checkboxes like this:

<div v-for="doc in documents_all" :key="doc.id">
	<input type="checkbox"
	:id="doc.id"
	:value="doc"
	v-model="form.documents"
	>
	<label for="doc.id"> 
		{{ doc.name }} 
	</label>
</div>

Can anyone see what I'm doing wrong?

0 likes
2 replies
tykus's avatar

You are setting the value as an Object; is the initial state also an Object with the same structure / state?

Robert Emil Berge's avatar

@tykus Yes, I think that's what I'm doing. Both "form.documents" and "documents_all" are arrays of objects with the same structure.

Please or to participate in this conversation.