Having this checkbox in a form(+ a textarea)
<save-numbers id="save-numbers" inline-template>
<div>
<label class="inline-block text-gray-500 font-bold mb-4">
<input class="mr-2 leading-tight" type="checkbox" name="saveNumbers" id="saveNumbers" v-model="toggle" {{ old('saveNumbers') ? 'checked' : '' }}/>
</label>
<div>
<textarea
:class="{ hidden: !toggle }"
class="w-full bg-gray-200 text-gray-700 border @error('notes') border-red-500 @enderror rounded py-3 px-4 mb-3 focus:outline-none focus:bg-white"
name="notes" id="notes" cols="30" rows="1"
placeholder="Add some notes">{{ old('notes', $validatedData['notes'] ?? '') }}</textarea>
</div>
</div>
</save-numbers>
How do I initialize/update the data on page load on form validation failure, so that the checkbox is checked? By default is not checked but if the form fails and the box was checked the checked attribute is not set in the VueJs component.
Here's the VueJs code
if (document.getElementById("save-numbers")) {
Vue.component('save-numbers', {
mounted: () => {
},
data() {
return {
title: 'Check me',
toggle: false,
}
},
methods: {
},
});
new Vue({ el: '#save-numbers' })
}
I want to detect if the checked attribute is set and update the toggle accordingly.
Thank you