In Vue.js, how do I unlink an array of radio buttons?
up vote
0
down vote
favorite
With reference to the following Plunkr:
https://plnkr.co/edit/zbOBDEaWvn8Tw0F0O9cy?p=preview
The radio buttons are linked, because clicking 'Yes' checks both 'Yes' radio buttons, and checking 'No' checks both 'No' radio buttons.
In my data model, I have an array with two separate rows:
terms: [
{termBoolean: 'Yes'},
{termBoolean: 'No'}
]
How do I structure my code so that the rows are not linked, and I can check one 'Yes' and one 'No' at a time?
vue.js
add a comment |
up vote
0
down vote
favorite
With reference to the following Plunkr:
https://plnkr.co/edit/zbOBDEaWvn8Tw0F0O9cy?p=preview
The radio buttons are linked, because clicking 'Yes' checks both 'Yes' radio buttons, and checking 'No' checks both 'No' radio buttons.
In my data model, I have an array with two separate rows:
terms: [
{termBoolean: 'Yes'},
{termBoolean: 'No'}
]
How do I structure my code so that the rows are not linked, and I can check one 'Yes' and one 'No' at a time?
vue.js
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
With reference to the following Plunkr:
https://plnkr.co/edit/zbOBDEaWvn8Tw0F0O9cy?p=preview
The radio buttons are linked, because clicking 'Yes' checks both 'Yes' radio buttons, and checking 'No' checks both 'No' radio buttons.
In my data model, I have an array with two separate rows:
terms: [
{termBoolean: 'Yes'},
{termBoolean: 'No'}
]
How do I structure my code so that the rows are not linked, and I can check one 'Yes' and one 'No' at a time?
vue.js
With reference to the following Plunkr:
https://plnkr.co/edit/zbOBDEaWvn8Tw0F0O9cy?p=preview
The radio buttons are linked, because clicking 'Yes' checks both 'Yes' radio buttons, and checking 'No' checks both 'No' radio buttons.
In my data model, I have an array with two separate rows:
terms: [
{termBoolean: 'Yes'},
{termBoolean: 'No'}
]
How do I structure my code so that the rows are not linked, and I can check one 'Yes' and one 'No' at a time?
vue.js
vue.js
asked Nov 22 at 5:41
Mary
14219
14219
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
Edit: My original answer was incorrect. Your problem is due to the version of Vue you're using, i.e. version 1.0.26. In version 1 of Vue, there was no (term, index)
syntactic sugar. Instead, index
was accessed via the special property $index
. My earlier answer was not applicable for this version of Vue.
To fix your current code, please make the following change:
<template v-for="term in terms">
<label>
<input type="radio" value="Yes" v-model="terms[$index].termBoolean" />Yes
<input type="radio" value="No" v-model="terms[$index].termBoolean" />No
</label><br>
</template>
Alternatively, upgrade to Vue 2.x. If you choose to go this route, please review the migration guide.
Came to the same conclusion after putting some debug code within the HTML<pre>{{ terms | json }}</pre>
. Values were wrong and using$index
looks cleaner.
– Yoram de Langen
Nov 22 at 7:13
add a comment |
up vote
0
down vote
<template v-for="(index, term) in terms">
EDIT : think you misordered the index and the term.
Ordering of(term, index)
was correct. The swapped order may work, but is semantically incorrect.
– B. Fleming
Nov 22 at 6:40
I just checked the documentary, and you are right, the index goes in the second parameter.
– securenova
Nov 22 at 6:50
We were both approaching the problem wrong, though. That's for version 2 of Vue. The question is using version 1. There was no such index syntax, instead requiring the use of the special$index
property provided by Vue.
– B. Fleming
Nov 22 at 7:05
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Edit: My original answer was incorrect. Your problem is due to the version of Vue you're using, i.e. version 1.0.26. In version 1 of Vue, there was no (term, index)
syntactic sugar. Instead, index
was accessed via the special property $index
. My earlier answer was not applicable for this version of Vue.
To fix your current code, please make the following change:
<template v-for="term in terms">
<label>
<input type="radio" value="Yes" v-model="terms[$index].termBoolean" />Yes
<input type="radio" value="No" v-model="terms[$index].termBoolean" />No
</label><br>
</template>
Alternatively, upgrade to Vue 2.x. If you choose to go this route, please review the migration guide.
Came to the same conclusion after putting some debug code within the HTML<pre>{{ terms | json }}</pre>
. Values were wrong and using$index
looks cleaner.
– Yoram de Langen
Nov 22 at 7:13
add a comment |
up vote
1
down vote
Edit: My original answer was incorrect. Your problem is due to the version of Vue you're using, i.e. version 1.0.26. In version 1 of Vue, there was no (term, index)
syntactic sugar. Instead, index
was accessed via the special property $index
. My earlier answer was not applicable for this version of Vue.
To fix your current code, please make the following change:
<template v-for="term in terms">
<label>
<input type="radio" value="Yes" v-model="terms[$index].termBoolean" />Yes
<input type="radio" value="No" v-model="terms[$index].termBoolean" />No
</label><br>
</template>
Alternatively, upgrade to Vue 2.x. If you choose to go this route, please review the migration guide.
Came to the same conclusion after putting some debug code within the HTML<pre>{{ terms | json }}</pre>
. Values were wrong and using$index
looks cleaner.
– Yoram de Langen
Nov 22 at 7:13
add a comment |
up vote
1
down vote
up vote
1
down vote
Edit: My original answer was incorrect. Your problem is due to the version of Vue you're using, i.e. version 1.0.26. In version 1 of Vue, there was no (term, index)
syntactic sugar. Instead, index
was accessed via the special property $index
. My earlier answer was not applicable for this version of Vue.
To fix your current code, please make the following change:
<template v-for="term in terms">
<label>
<input type="radio" value="Yes" v-model="terms[$index].termBoolean" />Yes
<input type="radio" value="No" v-model="terms[$index].termBoolean" />No
</label><br>
</template>
Alternatively, upgrade to Vue 2.x. If you choose to go this route, please review the migration guide.
Edit: My original answer was incorrect. Your problem is due to the version of Vue you're using, i.e. version 1.0.26. In version 1 of Vue, there was no (term, index)
syntactic sugar. Instead, index
was accessed via the special property $index
. My earlier answer was not applicable for this version of Vue.
To fix your current code, please make the following change:
<template v-for="term in terms">
<label>
<input type="radio" value="Yes" v-model="terms[$index].termBoolean" />Yes
<input type="radio" value="No" v-model="terms[$index].termBoolean" />No
</label><br>
</template>
Alternatively, upgrade to Vue 2.x. If you choose to go this route, please review the migration guide.
edited Nov 22 at 7:06
answered Nov 22 at 6:44
B. Fleming
2,3271515
2,3271515
Came to the same conclusion after putting some debug code within the HTML<pre>{{ terms | json }}</pre>
. Values were wrong and using$index
looks cleaner.
– Yoram de Langen
Nov 22 at 7:13
add a comment |
Came to the same conclusion after putting some debug code within the HTML<pre>{{ terms | json }}</pre>
. Values were wrong and using$index
looks cleaner.
– Yoram de Langen
Nov 22 at 7:13
Came to the same conclusion after putting some debug code within the HTML
<pre>{{ terms | json }}</pre>
. Values were wrong and using $index
looks cleaner.– Yoram de Langen
Nov 22 at 7:13
Came to the same conclusion after putting some debug code within the HTML
<pre>{{ terms | json }}</pre>
. Values were wrong and using $index
looks cleaner.– Yoram de Langen
Nov 22 at 7:13
add a comment |
up vote
0
down vote
<template v-for="(index, term) in terms">
EDIT : think you misordered the index and the term.
Ordering of(term, index)
was correct. The swapped order may work, but is semantically incorrect.
– B. Fleming
Nov 22 at 6:40
I just checked the documentary, and you are right, the index goes in the second parameter.
– securenova
Nov 22 at 6:50
We were both approaching the problem wrong, though. That's for version 2 of Vue. The question is using version 1. There was no such index syntax, instead requiring the use of the special$index
property provided by Vue.
– B. Fleming
Nov 22 at 7:05
add a comment |
up vote
0
down vote
<template v-for="(index, term) in terms">
EDIT : think you misordered the index and the term.
Ordering of(term, index)
was correct. The swapped order may work, but is semantically incorrect.
– B. Fleming
Nov 22 at 6:40
I just checked the documentary, and you are right, the index goes in the second parameter.
– securenova
Nov 22 at 6:50
We were both approaching the problem wrong, though. That's for version 2 of Vue. The question is using version 1. There was no such index syntax, instead requiring the use of the special$index
property provided by Vue.
– B. Fleming
Nov 22 at 7:05
add a comment |
up vote
0
down vote
up vote
0
down vote
<template v-for="(index, term) in terms">
EDIT : think you misordered the index and the term.
<template v-for="(index, term) in terms">
EDIT : think you misordered the index and the term.
answered Nov 22 at 6:34
securenova
72113
72113
Ordering of(term, index)
was correct. The swapped order may work, but is semantically incorrect.
– B. Fleming
Nov 22 at 6:40
I just checked the documentary, and you are right, the index goes in the second parameter.
– securenova
Nov 22 at 6:50
We were both approaching the problem wrong, though. That's for version 2 of Vue. The question is using version 1. There was no such index syntax, instead requiring the use of the special$index
property provided by Vue.
– B. Fleming
Nov 22 at 7:05
add a comment |
Ordering of(term, index)
was correct. The swapped order may work, but is semantically incorrect.
– B. Fleming
Nov 22 at 6:40
I just checked the documentary, and you are right, the index goes in the second parameter.
– securenova
Nov 22 at 6:50
We were both approaching the problem wrong, though. That's for version 2 of Vue. The question is using version 1. There was no such index syntax, instead requiring the use of the special$index
property provided by Vue.
– B. Fleming
Nov 22 at 7:05
Ordering of
(term, index)
was correct. The swapped order may work, but is semantically incorrect.– B. Fleming
Nov 22 at 6:40
Ordering of
(term, index)
was correct. The swapped order may work, but is semantically incorrect.– B. Fleming
Nov 22 at 6:40
I just checked the documentary, and you are right, the index goes in the second parameter.
– securenova
Nov 22 at 6:50
I just checked the documentary, and you are right, the index goes in the second parameter.
– securenova
Nov 22 at 6:50
We were both approaching the problem wrong, though. That's for version 2 of Vue. The question is using version 1. There was no such index syntax, instead requiring the use of the special
$index
property provided by Vue.– B. Fleming
Nov 22 at 7:05
We were both approaching the problem wrong, though. That's for version 2 of Vue. The question is using version 1. There was no such index syntax, instead requiring the use of the special
$index
property provided by Vue.– B. Fleming
Nov 22 at 7:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424533%2fin-vue-js-how-do-i-unlink-an-array-of-radio-buttons%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown