Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/checkbox-true-false-value-form-submission.md
1---2title: Checkbox true-value/false-value Not Submitted in Forms3impact: MEDIUM4impactDescription: true-value and false-value attributes don't affect form submission - unchecked boxes send nothing5type: capability6tags: [vue3, v-model, forms, checkbox, form-submission]7---89# Checkbox true-value/false-value Not Submitted in Forms1011**Impact: MEDIUM** - Vue's `true-value` and `false-value` attributes only affect the JavaScript binding, NOT the actual form submission. Unchecked checkboxes are never included in form submissions by browsers, regardless of `false-value`.1213This is a browser limitation, not a Vue issue. If you need to submit one of two values (like "yes"/"no" or "active"/"inactive"), use radio buttons instead of a checkbox.1415## Task Checklist1617- [ ] Don't rely on `false-value` for form submissions - it won't be sent18- [ ] Use radio buttons when you need to submit one of exactly two values19- [ ] Remember `true-value`/`false-value` are for JavaScript state only20- [ ] For form submissions with custom values, handle the transformation server-side or in submit handler2122**Problem - false-value not submitted:**23```html24<script setup>25import { ref } from 'vue'2627const status = ref('no') // JavaScript value works correctly28</script>2930<template>31<form action="/api/update" method="POST">32<!-- PROBLEM: When unchecked, nothing is submitted for this field -->33<!-- Server receives no "status" field at all, not "no" -->34<input35type="checkbox"36v-model="status"37true-value="yes"38false-value="no"39name="status"40>41<label>Active</label>4243<!-- status.value correctly shows "yes" or "no" in Vue -->44<!-- But form submission only sends "status=yes" when checked -->45<!-- When unchecked, "status" field is completely missing -->46</form>47</template>48```4950**Solution 1 - Use radio buttons for two-value submission:**51```html52<script setup>53import { ref } from 'vue'5455const status = ref('no')56</script>5758<template>59<form action="/api/update" method="POST">60<!-- CORRECT: Radio buttons always submit a value -->61<label>62<input type="radio" v-model="status" value="yes" name="status">63Active64</label>65<label>66<input type="radio" v-model="status" value="no" name="status">67Inactive68</label>6970<!-- Form always submits "status=yes" or "status=no" -->71</form>72</template>73```7475**Solution 2 - Handle in submit handler (for SPA/AJAX):**76```html77<script setup>78import { ref } from 'vue'7980const isActive = ref(false)8182async function submitForm() {83// Transform checkbox state to desired value before sending84const payload = {85status: isActive.value ? 'yes' : 'no'86}8788await fetch('/api/update', {89method: 'POST',90body: JSON.stringify(payload)91})92}93</script>9495<template>96<!-- For AJAX submission, checkbox is fine - transform in handler -->97<input type="checkbox" v-model="isActive">98<label>Active</label>99100<button @click="submitForm">Save</button>101</template>102```103104**Solution 3 - Hidden input fallback:**105```html106<template>107<form action="/api/update" method="POST">108<!-- Hidden input provides fallback value -->109<input type="hidden" name="status" value="no">110<!-- Checkbox overrides with "yes" when checked -->111<input type="checkbox" name="status" value="yes" v-model="isActive">112<label>Active</label>113</form>114</template>115```116117## Reference118- [Vue.js Form Input Bindings - Checkbox](https://vuejs.org/guide/essentials/forms.html#checkbox)119