Changing fields generated with v-for is updating other entries












0















I am having an issue with my fields generated with v-for, where the fields I have generated are affecting all the objects I am passing through the v-for loop.



I have created a unique identifier for each object, but for some reason v-model is treating it as the same object.



Here is the Vue snippet which outputs the generated fields:



<div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities">
<div class="col-3">
<v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
<input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', index)"
:value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
</div>
<div class="col-2">
<v-datepicker :name="setOpportunityFieldName('date', index)" v-model="opportunity.date" placeholder="Date"></v-datepicker>
</div>
<div class="col-2">
<input type="time" :name="setOpportunityFieldName('start_time', index)" v-model="opportunity.start_time" v-validate="'required'"
:class="{'vee-error-field' : errors.has(setOpportunityFieldName('start_time', index))}" class="bnfo-database-fields-border"
step="900" title="Shift Start Time"/>
</div>
<div class="col-2">
<input type="time" :name="setOpportunityFieldName('end_time', index)" v-model="opportunity.end_time" v-validate="'required'"
:class="{'vee-error-field' : errors.has(setOpportunityFieldName('end_time', index))}" class="bnfo-database-fields-border" step="900"
title="Shift End Date">
</div>
<div class="col-1">
<input type="number" :name="setOpportunityFieldName('max_par_req', index)" v-model.number="opportunity.max_par_req" v-validate="'required|min_value:1'"
:class="{'vee-error-field' : errors.has(setOpportunityFieldName('max_par_req', index))}"
class="bnfo-database-fields-border" title="Shift's Maximum Participants">
</div>
<div class="col-1 text-center">
<v-delete-button :entries="opportunities" :entry-key="index"></v-delete-button>
</div>
</div>
</div>


Here is the object I am passing through the v-for as 'opportunities'



enter image description here



I would like the fields generated to update each object in 'opportunitues' independently via v-model.



Any help or suggestions are greatly appreciated! ^^










share|improve this question



























    0















    I am having an issue with my fields generated with v-for, where the fields I have generated are affecting all the objects I am passing through the v-for loop.



    I have created a unique identifier for each object, but for some reason v-model is treating it as the same object.



    Here is the Vue snippet which outputs the generated fields:



    <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities">
    <div class="col-3">
    <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
    <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', index)"
    :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
    </div>
    <div class="col-2">
    <v-datepicker :name="setOpportunityFieldName('date', index)" v-model="opportunity.date" placeholder="Date"></v-datepicker>
    </div>
    <div class="col-2">
    <input type="time" :name="setOpportunityFieldName('start_time', index)" v-model="opportunity.start_time" v-validate="'required'"
    :class="{'vee-error-field' : errors.has(setOpportunityFieldName('start_time', index))}" class="bnfo-database-fields-border"
    step="900" title="Shift Start Time"/>
    </div>
    <div class="col-2">
    <input type="time" :name="setOpportunityFieldName('end_time', index)" v-model="opportunity.end_time" v-validate="'required'"
    :class="{'vee-error-field' : errors.has(setOpportunityFieldName('end_time', index))}" class="bnfo-database-fields-border" step="900"
    title="Shift End Date">
    </div>
    <div class="col-1">
    <input type="number" :name="setOpportunityFieldName('max_par_req', index)" v-model.number="opportunity.max_par_req" v-validate="'required|min_value:1'"
    :class="{'vee-error-field' : errors.has(setOpportunityFieldName('max_par_req', index))}"
    class="bnfo-database-fields-border" title="Shift's Maximum Participants">
    </div>
    <div class="col-1 text-center">
    <v-delete-button :entries="opportunities" :entry-key="index"></v-delete-button>
    </div>
    </div>
    </div>


    Here is the object I am passing through the v-for as 'opportunities'



    enter image description here



    I would like the fields generated to update each object in 'opportunitues' independently via v-model.



    Any help or suggestions are greatly appreciated! ^^










    share|improve this question

























      0












      0








      0








      I am having an issue with my fields generated with v-for, where the fields I have generated are affecting all the objects I am passing through the v-for loop.



      I have created a unique identifier for each object, but for some reason v-model is treating it as the same object.



      Here is the Vue snippet which outputs the generated fields:



      <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities">
      <div class="col-3">
      <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
      <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', index)"
      :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
      </div>
      <div class="col-2">
      <v-datepicker :name="setOpportunityFieldName('date', index)" v-model="opportunity.date" placeholder="Date"></v-datepicker>
      </div>
      <div class="col-2">
      <input type="time" :name="setOpportunityFieldName('start_time', index)" v-model="opportunity.start_time" v-validate="'required'"
      :class="{'vee-error-field' : errors.has(setOpportunityFieldName('start_time', index))}" class="bnfo-database-fields-border"
      step="900" title="Shift Start Time"/>
      </div>
      <div class="col-2">
      <input type="time" :name="setOpportunityFieldName('end_time', index)" v-model="opportunity.end_time" v-validate="'required'"
      :class="{'vee-error-field' : errors.has(setOpportunityFieldName('end_time', index))}" class="bnfo-database-fields-border" step="900"
      title="Shift End Date">
      </div>
      <div class="col-1">
      <input type="number" :name="setOpportunityFieldName('max_par_req', index)" v-model.number="opportunity.max_par_req" v-validate="'required|min_value:1'"
      :class="{'vee-error-field' : errors.has(setOpportunityFieldName('max_par_req', index))}"
      class="bnfo-database-fields-border" title="Shift's Maximum Participants">
      </div>
      <div class="col-1 text-center">
      <v-delete-button :entries="opportunities" :entry-key="index"></v-delete-button>
      </div>
      </div>
      </div>


      Here is the object I am passing through the v-for as 'opportunities'



      enter image description here



      I would like the fields generated to update each object in 'opportunitues' independently via v-model.



      Any help or suggestions are greatly appreciated! ^^










      share|improve this question














      I am having an issue with my fields generated with v-for, where the fields I have generated are affecting all the objects I am passing through the v-for loop.



      I have created a unique identifier for each object, but for some reason v-model is treating it as the same object.



      Here is the Vue snippet which outputs the generated fields:



      <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities">
      <div class="col-3">
      <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
      <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', index)"
      :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
      </div>
      <div class="col-2">
      <v-datepicker :name="setOpportunityFieldName('date', index)" v-model="opportunity.date" placeholder="Date"></v-datepicker>
      </div>
      <div class="col-2">
      <input type="time" :name="setOpportunityFieldName('start_time', index)" v-model="opportunity.start_time" v-validate="'required'"
      :class="{'vee-error-field' : errors.has(setOpportunityFieldName('start_time', index))}" class="bnfo-database-fields-border"
      step="900" title="Shift Start Time"/>
      </div>
      <div class="col-2">
      <input type="time" :name="setOpportunityFieldName('end_time', index)" v-model="opportunity.end_time" v-validate="'required'"
      :class="{'vee-error-field' : errors.has(setOpportunityFieldName('end_time', index))}" class="bnfo-database-fields-border" step="900"
      title="Shift End Date">
      </div>
      <div class="col-1">
      <input type="number" :name="setOpportunityFieldName('max_par_req', index)" v-model.number="opportunity.max_par_req" v-validate="'required|min_value:1'"
      :class="{'vee-error-field' : errors.has(setOpportunityFieldName('max_par_req', index))}"
      class="bnfo-database-fields-border" title="Shift's Maximum Participants">
      </div>
      <div class="col-1 text-center">
      <v-delete-button :entries="opportunities" :entry-key="index"></v-delete-button>
      </div>
      </div>
      </div>


      Here is the object I am passing through the v-for as 'opportunities'



      enter image description here



      I would like the fields generated to update each object in 'opportunitues' independently via v-model.



      Any help or suggestions are greatly appreciated! ^^







      javascript vue.js vuejs2 v-for






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 15:51









      Josh GomesJosh Gomes

      688




      688
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Try to add :key="index" here



          <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities" :key="index">







          share|improve this answer


























          • Hasn't seemed to solve the issue unfortunately :(

            – Josh Gomes
            Nov 13 '18 at 15:59






          • 1





            What's exactly wrong now?

            – Ishikawa Yoshi
            Nov 13 '18 at 16:02











          • It is still updating the other entries when I change the field for one of the entries

            – Josh Gomes
            Nov 13 '18 at 16:06



















          0














          I fixed it!



          I stored the opportunities in an array instead of an object.



          For some reason v-model was behaving weird when the opportunities were stored in the object.



          Here is the structure for the array which contained the objects:



          enter image description here



          Here is the v-for loop I used:



          <div class="row margin-15-bot margin-15-top" v-for="(opportunity, key) in opportunities" :key="opportunity.id">
          <div class="col-3">
          <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
          <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', key)"
          :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
          </div>


          This is the method I used to add the entries to the array:



          addEntry: function(entries, entryValue) {
          entries.push(entryValue());
          this.entryCount++;
          }





          share|improve this answer























            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%2f53284696%2fchanging-fields-generated-with-v-for-is-updating-other-entries%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









            0














            Try to add :key="index" here



            <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities" :key="index">







            share|improve this answer


























            • Hasn't seemed to solve the issue unfortunately :(

              – Josh Gomes
              Nov 13 '18 at 15:59






            • 1





              What's exactly wrong now?

              – Ishikawa Yoshi
              Nov 13 '18 at 16:02











            • It is still updating the other entries when I change the field for one of the entries

              – Josh Gomes
              Nov 13 '18 at 16:06
















            0














            Try to add :key="index" here



            <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities" :key="index">







            share|improve this answer


























            • Hasn't seemed to solve the issue unfortunately :(

              – Josh Gomes
              Nov 13 '18 at 15:59






            • 1





              What's exactly wrong now?

              – Ishikawa Yoshi
              Nov 13 '18 at 16:02











            • It is still updating the other entries when I change the field for one of the entries

              – Josh Gomes
              Nov 13 '18 at 16:06














            0












            0








            0







            Try to add :key="index" here



            <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities" :key="index">







            share|improve this answer















            Try to add :key="index" here



            <div class="row margin-15-bot margin-15-top" v-for="(opportunity, index) in opportunities" :key="index">








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 13 '18 at 16:03

























            answered Nov 13 '18 at 15:53









            Ishikawa YoshiIshikawa Yoshi

            1,02541740




            1,02541740













            • Hasn't seemed to solve the issue unfortunately :(

              – Josh Gomes
              Nov 13 '18 at 15:59






            • 1





              What's exactly wrong now?

              – Ishikawa Yoshi
              Nov 13 '18 at 16:02











            • It is still updating the other entries when I change the field for one of the entries

              – Josh Gomes
              Nov 13 '18 at 16:06



















            • Hasn't seemed to solve the issue unfortunately :(

              – Josh Gomes
              Nov 13 '18 at 15:59






            • 1





              What's exactly wrong now?

              – Ishikawa Yoshi
              Nov 13 '18 at 16:02











            • It is still updating the other entries when I change the field for one of the entries

              – Josh Gomes
              Nov 13 '18 at 16:06

















            Hasn't seemed to solve the issue unfortunately :(

            – Josh Gomes
            Nov 13 '18 at 15:59





            Hasn't seemed to solve the issue unfortunately :(

            – Josh Gomes
            Nov 13 '18 at 15:59




            1




            1





            What's exactly wrong now?

            – Ishikawa Yoshi
            Nov 13 '18 at 16:02





            What's exactly wrong now?

            – Ishikawa Yoshi
            Nov 13 '18 at 16:02













            It is still updating the other entries when I change the field for one of the entries

            – Josh Gomes
            Nov 13 '18 at 16:06





            It is still updating the other entries when I change the field for one of the entries

            – Josh Gomes
            Nov 13 '18 at 16:06













            0














            I fixed it!



            I stored the opportunities in an array instead of an object.



            For some reason v-model was behaving weird when the opportunities were stored in the object.



            Here is the structure for the array which contained the objects:



            enter image description here



            Here is the v-for loop I used:



            <div class="row margin-15-bot margin-15-top" v-for="(opportunity, key) in opportunities" :key="opportunity.id">
            <div class="col-3">
            <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
            <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', key)"
            :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
            </div>


            This is the method I used to add the entries to the array:



            addEntry: function(entries, entryValue) {
            entries.push(entryValue());
            this.entryCount++;
            }





            share|improve this answer




























              0














              I fixed it!



              I stored the opportunities in an array instead of an object.



              For some reason v-model was behaving weird when the opportunities were stored in the object.



              Here is the structure for the array which contained the objects:



              enter image description here



              Here is the v-for loop I used:



              <div class="row margin-15-bot margin-15-top" v-for="(opportunity, key) in opportunities" :key="opportunity.id">
              <div class="col-3">
              <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
              <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', key)"
              :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
              </div>


              This is the method I used to add the entries to the array:



              addEntry: function(entries, entryValue) {
              entries.push(entryValue());
              this.entryCount++;
              }





              share|improve this answer


























                0












                0








                0







                I fixed it!



                I stored the opportunities in an array instead of an object.



                For some reason v-model was behaving weird when the opportunities were stored in the object.



                Here is the structure for the array which contained the objects:



                enter image description here



                Here is the v-for loop I used:



                <div class="row margin-15-bot margin-15-top" v-for="(opportunity, key) in opportunities" :key="opportunity.id">
                <div class="col-3">
                <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
                <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', key)"
                :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
                </div>


                This is the method I used to add the entries to the array:



                addEntry: function(entries, entryValue) {
                entries.push(entryValue());
                this.entryCount++;
                }





                share|improve this answer













                I fixed it!



                I stored the opportunities in an array instead of an object.



                For some reason v-model was behaving weird when the opportunities were stored in the object.



                Here is the structure for the array which contained the objects:



                enter image description here



                Here is the v-for loop I used:



                <div class="row margin-15-bot margin-15-top" v-for="(opportunity, key) in opportunities" :key="opportunity.id">
                <div class="col-3">
                <v-select :options="opportunityChoices" v-model="opportunity.bookable_opportunity_ID" placeholder="Select Charity"></v-select>
                <input title="Select an Opportunity" :name="setOpportunityFieldName('bookable_opportunity_ID', key)"
                :value="opportunity.bookable_opportunity_ID.id ? opportunity.bookable_opportunity_ID.id : 0" type="text" hidden/>
                </div>


                This is the method I used to add the entries to the array:



                addEntry: function(entries, entryValue) {
                entries.push(entryValue());
                this.entryCount++;
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 15:52









                Josh GomesJosh Gomes

                688




                688






























                    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%2f53284696%2fchanging-fields-generated-with-v-for-is-updating-other-entries%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

                    Full-time equivalent

                    さくらももこ

                    13 indicted, 8 arrested in Calif. drug cartel investigation