Duplicate 'value' attribute for <input type="radio"> when using it with v-model
See original GitHub issueThe following TypeScript error is thrown:
error TS17001: JSX elements cannot have multiple attributes with the same name.
value="One"
~~~~~
for the following template (inspired from https://vuejs.org/guide/essentials/forms.html#radio):
<template>
<input v-model="picked" type="radio" value="One" />
<input v-model="checked" type="checkbox" value="Two" />
</template>
<script setup lang="ts">
import { ref } from "vue"
const picked = ref([])
const checked = ref([])
</script>
Volar special-cases the <input type="checkbox">
case which works, but not the <input type="radio">
:
function getModelValuePropName(node: CompilerDOM.ElementNode, vueVersion: number) {
const tag = node.tag;
const typeAttr = node.props.find(prop => prop.type === CompilerDOM.NodeTypes.ATTRIBUTE && prop.name === 'type');
const type = typeAttr?.value?.content;
// >>>
if (tag === 'input' && type === 'checkbox')
return 'checked';
// >>>>>
if (
tag === 'input' ||
tag === 'textarea' ||
tag === 'select' ||
vueVersion < 3
) return 'value';
return 'modelValue';
}
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5
Top Results From Across the Web
vue.js - How to get radio button value from multiple radio ...
Put the value of each radio group in the object in the array, and then calculate the selected value by computed . Share....
Read more >Using v-model for Two-Way Binding in Vue.js | DigitalOcean
To bind the value of an input element to a property of your component's data, use v-model="dataProperty" like so.
Read more >Form Input Bindings - Vue.js
v -model will ignore the initial value , checked or selected attributes found on any form elements. It will always treat the current...
Read more >x-model - Alpine.js
x-model allows you to bind the value of an input element to Alpine data. Here's a simple example of using x-model to bind...
Read more >vuejs v-for radio list and checked value - Laracasts
I have a component and I need to loop through an array of values to create a radio list (v-for is perfect) and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, this is just invalid. v-model already handles
checked
, so you should not add it yourself.Got same error, when using
v-model
andvalue
at same time like this:vue: 2.7 volar: 0.40.2/0.40.3/0.40.4
tsconfig.json:
Temporary solution: Downgrade to
0.40.1
.