'On Vue.js v-model does not keep the value when the user hits the back button
I have a form with checkboxes. When the user marks them as checked I add the value to a vue.js prop.
If the user submits the form and then presses the back button, the boxes checked stay the same but the vue.js variable does not contain the checked values anymore. If I uncheck them and check them again manually then they show up in the variable again.
How can I keep the values in the variable or make the checkboxes unchecked so the user knows that needs to check them again?
HTML
{% for entity in entities %}
<input type="checkbox" v-model="checkedEntities" value='{{ entity.id }}' name="entity_{{ entity.id }}">
<span>{{ entity.name_tag }}</span>
{% endfor %}
Vue.js
var app = new Vue({
el: '#app',
delimiters: ["${","}"],
data: {
checkedEntities: [],
}
}
Note: the entity variable belongs to Django.
Solution 1:[1]
it's a chrome bug that can be fixed by turning off autocomplete for the radio button:
<input type="checkbox" autocomplete="off" v-model="checkedEntities" value='{{ entity.id }}' name="entity_{{ entity.id }}">
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |