In Vue.js, how do I unlink an array of radio buttons?












0















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?










share|improve this question



























    0















    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?










    share|improve this question

























      0












      0








      0








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 5:41









      MaryMary

      17719




      17719
























          2 Answers
          2






          active

          oldest

          votes


















          1














          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.






          share|improve this answer


























          • 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 '18 at 7:13



















          0














           <template v-for="(index, term) in terms">


          EDIT : think you misordered the index and the term.






          share|improve this answer
























          • Ordering of (term, index) was correct. The swapped order may work, but is semantically incorrect.

            – B. Fleming
            Nov 22 '18 at 6:40











          • I just checked the documentary, and you are right, the index goes in the second parameter.

            – securenova
            Nov 22 '18 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 '18 at 7:05











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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.






          share|improve this answer


























          • 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 '18 at 7:13
















          1














          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.






          share|improve this answer


























          • 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 '18 at 7:13














          1












          1








          1







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 7:06

























          answered Nov 22 '18 at 6:44









          B. FlemingB. Fleming

          2,5321516




          2,5321516













          • 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 '18 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 '18 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 '18 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 '18 at 7:13













          0














           <template v-for="(index, term) in terms">


          EDIT : think you misordered the index and the term.






          share|improve this answer
























          • Ordering of (term, index) was correct. The swapped order may work, but is semantically incorrect.

            – B. Fleming
            Nov 22 '18 at 6:40











          • I just checked the documentary, and you are right, the index goes in the second parameter.

            – securenova
            Nov 22 '18 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 '18 at 7:05
















          0














           <template v-for="(index, term) in terms">


          EDIT : think you misordered the index and the term.






          share|improve this answer
























          • Ordering of (term, index) was correct. The swapped order may work, but is semantically incorrect.

            – B. Fleming
            Nov 22 '18 at 6:40











          • I just checked the documentary, and you are right, the index goes in the second parameter.

            – securenova
            Nov 22 '18 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 '18 at 7:05














          0












          0








          0







           <template v-for="(index, term) in terms">


          EDIT : think you misordered the index and the term.






          share|improve this answer













           <template v-for="(index, term) in terms">


          EDIT : think you misordered the index and the term.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 6:34









          securenovasecurenova

          72213




          72213













          • Ordering of (term, index) was correct. The swapped order may work, but is semantically incorrect.

            – B. Fleming
            Nov 22 '18 at 6:40











          • I just checked the documentary, and you are right, the index goes in the second parameter.

            – securenova
            Nov 22 '18 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 '18 at 7:05



















          • Ordering of (term, index) was correct. The swapped order may work, but is semantically incorrect.

            – B. Fleming
            Nov 22 '18 at 6:40











          • I just checked the documentary, and you are right, the index goes in the second parameter.

            – securenova
            Nov 22 '18 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 '18 at 7:05

















          Ordering of (term, index) was correct. The swapped order may work, but is semantically incorrect.

          – B. Fleming
          Nov 22 '18 at 6:40





          Ordering of (term, index) was correct. The swapped order may work, but is semantically incorrect.

          – B. Fleming
          Nov 22 '18 at 6:40













          I just checked the documentary, and you are right, the index goes in the second parameter.

          – securenova
          Nov 22 '18 at 6:50





          I just checked the documentary, and you are right, the index goes in the second parameter.

          – securenova
          Nov 22 '18 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 '18 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 '18 at 7:05


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen