Retrieve index of just one element in v-for loop












1














Based on the validation response from a text-field I'm trying to disable or enable ONE button based on its index in my v-for loop. However, right now I'm disabling BOTH buttons.



My idea was to get the index of the button based on the info in my v-for loop. However when I try and get the index of the button the v-for loop is running and it returns the indices of both buttons.



So my question is how to get the index of just one button, the button that is in the same form as the text-field that is returning the error.



(link to code running at the bottom of my code samples)



Here is my template code:



<template>
<v-container fluid grid-list-lg class="come_closer">
<v-layout row wrap>
<v-flex xs12 v-for="(creds, index) in amazonCredsArray" :key="creds.id" class="pb-4">
<v-card class="lightpurple">
<v-card-title>
<v-icon class="my_dark_purple_text">language</v-icon>
<h1 class="title oswald my_dark_purple_text pl-2 pr-5">ENTER YOUR AMAZON CREDENTIALS BELOW</h1>
</v-card-title>

<v-form ref="form" lazy-validation>
<v-layout xs12 row wrap class="mx-auto" >
<v-flex xs12>
<v-text-field
:rules="[sellerId]"
required
color="indigo"
label="Amazon Seller Id"
v-model="creds.seller_id"
prepend-icon="person"
></v-text-field>
</v-flex>


Here is the row where my button is:



<v-layout row wrap class="text-xs-center" v-if="show_cancel_button">
<v-flex xs6>
<v-btn
:id="creds.id"
block
large
class="my_dark_purple_btn"
dark
@click="formCheckAndSend()"
:class="{looks_disabled: isDisabled(creds, index)}"
>{{ whichTextToShow }}
</v-btn>
</v-flex>
<v-flex xs6>
<v-btn block outline large color="indigo" dark @click="sendBackToSpeeds">Cancel</v-btn>
</v-flex>
</v-layout>


Then here is my rule that is returning the error on that text-field. I was trying to pass in the index into it, but it wasn't working:



sellerId(value, index) {
if (value.length === 0) {
// this.disabled = true;
console.log("What's my value " + value + "and my index " + index);
return "What are you trying to do here?";
} else {
// this.disabled = false;
return true;
}
},


You can see my code running here










share|improve this question





























    1














    Based on the validation response from a text-field I'm trying to disable or enable ONE button based on its index in my v-for loop. However, right now I'm disabling BOTH buttons.



    My idea was to get the index of the button based on the info in my v-for loop. However when I try and get the index of the button the v-for loop is running and it returns the indices of both buttons.



    So my question is how to get the index of just one button, the button that is in the same form as the text-field that is returning the error.



    (link to code running at the bottom of my code samples)



    Here is my template code:



    <template>
    <v-container fluid grid-list-lg class="come_closer">
    <v-layout row wrap>
    <v-flex xs12 v-for="(creds, index) in amazonCredsArray" :key="creds.id" class="pb-4">
    <v-card class="lightpurple">
    <v-card-title>
    <v-icon class="my_dark_purple_text">language</v-icon>
    <h1 class="title oswald my_dark_purple_text pl-2 pr-5">ENTER YOUR AMAZON CREDENTIALS BELOW</h1>
    </v-card-title>

    <v-form ref="form" lazy-validation>
    <v-layout xs12 row wrap class="mx-auto" >
    <v-flex xs12>
    <v-text-field
    :rules="[sellerId]"
    required
    color="indigo"
    label="Amazon Seller Id"
    v-model="creds.seller_id"
    prepend-icon="person"
    ></v-text-field>
    </v-flex>


    Here is the row where my button is:



    <v-layout row wrap class="text-xs-center" v-if="show_cancel_button">
    <v-flex xs6>
    <v-btn
    :id="creds.id"
    block
    large
    class="my_dark_purple_btn"
    dark
    @click="formCheckAndSend()"
    :class="{looks_disabled: isDisabled(creds, index)}"
    >{{ whichTextToShow }}
    </v-btn>
    </v-flex>
    <v-flex xs6>
    <v-btn block outline large color="indigo" dark @click="sendBackToSpeeds">Cancel</v-btn>
    </v-flex>
    </v-layout>


    Then here is my rule that is returning the error on that text-field. I was trying to pass in the index into it, but it wasn't working:



    sellerId(value, index) {
    if (value.length === 0) {
    // this.disabled = true;
    console.log("What's my value " + value + "and my index " + index);
    return "What are you trying to do here?";
    } else {
    // this.disabled = false;
    return true;
    }
    },


    You can see my code running here










    share|improve this question



























      1












      1








      1







      Based on the validation response from a text-field I'm trying to disable or enable ONE button based on its index in my v-for loop. However, right now I'm disabling BOTH buttons.



      My idea was to get the index of the button based on the info in my v-for loop. However when I try and get the index of the button the v-for loop is running and it returns the indices of both buttons.



      So my question is how to get the index of just one button, the button that is in the same form as the text-field that is returning the error.



      (link to code running at the bottom of my code samples)



      Here is my template code:



      <template>
      <v-container fluid grid-list-lg class="come_closer">
      <v-layout row wrap>
      <v-flex xs12 v-for="(creds, index) in amazonCredsArray" :key="creds.id" class="pb-4">
      <v-card class="lightpurple">
      <v-card-title>
      <v-icon class="my_dark_purple_text">language</v-icon>
      <h1 class="title oswald my_dark_purple_text pl-2 pr-5">ENTER YOUR AMAZON CREDENTIALS BELOW</h1>
      </v-card-title>

      <v-form ref="form" lazy-validation>
      <v-layout xs12 row wrap class="mx-auto" >
      <v-flex xs12>
      <v-text-field
      :rules="[sellerId]"
      required
      color="indigo"
      label="Amazon Seller Id"
      v-model="creds.seller_id"
      prepend-icon="person"
      ></v-text-field>
      </v-flex>


      Here is the row where my button is:



      <v-layout row wrap class="text-xs-center" v-if="show_cancel_button">
      <v-flex xs6>
      <v-btn
      :id="creds.id"
      block
      large
      class="my_dark_purple_btn"
      dark
      @click="formCheckAndSend()"
      :class="{looks_disabled: isDisabled(creds, index)}"
      >{{ whichTextToShow }}
      </v-btn>
      </v-flex>
      <v-flex xs6>
      <v-btn block outline large color="indigo" dark @click="sendBackToSpeeds">Cancel</v-btn>
      </v-flex>
      </v-layout>


      Then here is my rule that is returning the error on that text-field. I was trying to pass in the index into it, but it wasn't working:



      sellerId(value, index) {
      if (value.length === 0) {
      // this.disabled = true;
      console.log("What's my value " + value + "and my index " + index);
      return "What are you trying to do here?";
      } else {
      // this.disabled = false;
      return true;
      }
      },


      You can see my code running here










      share|improve this question















      Based on the validation response from a text-field I'm trying to disable or enable ONE button based on its index in my v-for loop. However, right now I'm disabling BOTH buttons.



      My idea was to get the index of the button based on the info in my v-for loop. However when I try and get the index of the button the v-for loop is running and it returns the indices of both buttons.



      So my question is how to get the index of just one button, the button that is in the same form as the text-field that is returning the error.



      (link to code running at the bottom of my code samples)



      Here is my template code:



      <template>
      <v-container fluid grid-list-lg class="come_closer">
      <v-layout row wrap>
      <v-flex xs12 v-for="(creds, index) in amazonCredsArray" :key="creds.id" class="pb-4">
      <v-card class="lightpurple">
      <v-card-title>
      <v-icon class="my_dark_purple_text">language</v-icon>
      <h1 class="title oswald my_dark_purple_text pl-2 pr-5">ENTER YOUR AMAZON CREDENTIALS BELOW</h1>
      </v-card-title>

      <v-form ref="form" lazy-validation>
      <v-layout xs12 row wrap class="mx-auto" >
      <v-flex xs12>
      <v-text-field
      :rules="[sellerId]"
      required
      color="indigo"
      label="Amazon Seller Id"
      v-model="creds.seller_id"
      prepend-icon="person"
      ></v-text-field>
      </v-flex>


      Here is the row where my button is:



      <v-layout row wrap class="text-xs-center" v-if="show_cancel_button">
      <v-flex xs6>
      <v-btn
      :id="creds.id"
      block
      large
      class="my_dark_purple_btn"
      dark
      @click="formCheckAndSend()"
      :class="{looks_disabled: isDisabled(creds, index)}"
      >{{ whichTextToShow }}
      </v-btn>
      </v-flex>
      <v-flex xs6>
      <v-btn block outline large color="indigo" dark @click="sendBackToSpeeds">Cancel</v-btn>
      </v-flex>
      </v-layout>


      Then here is my rule that is returning the error on that text-field. I was trying to pass in the index into it, but it wasn't working:



      sellerId(value, index) {
      if (value.length === 0) {
      // this.disabled = true;
      console.log("What's my value " + value + "and my index " + index);
      return "What are you trying to do here?";
      } else {
      // this.disabled = false;
      return true;
      }
      },


      You can see my code running here







      javascript vue.js vuetify.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 15:09









      chazsolo

      5,1171233




      5,1171233










      asked Nov 19 '18 at 13:41









      ToddT

      7051724




      7051724
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can pass the index to the rule:



          <v-text-field :rules="[ v => sellerId(v, index) ]" ...></v-text-field>





          share|improve this answer





















          • thanks again @Psidom !
            – ToddT
            Nov 19 '18 at 16:14











          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%2f53375906%2fretrieve-index-of-just-one-element-in-v-for-loop%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can pass the index to the rule:



          <v-text-field :rules="[ v => sellerId(v, index) ]" ...></v-text-field>





          share|improve this answer





















          • thanks again @Psidom !
            – ToddT
            Nov 19 '18 at 16:14
















          1














          You can pass the index to the rule:



          <v-text-field :rules="[ v => sellerId(v, index) ]" ...></v-text-field>





          share|improve this answer





















          • thanks again @Psidom !
            – ToddT
            Nov 19 '18 at 16:14














          1












          1








          1






          You can pass the index to the rule:



          <v-text-field :rules="[ v => sellerId(v, index) ]" ...></v-text-field>





          share|improve this answer












          You can pass the index to the rule:



          <v-text-field :rules="[ v => sellerId(v, index) ]" ...></v-text-field>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 15:06









          Psidom

          122k1281125




          122k1281125












          • thanks again @Psidom !
            – ToddT
            Nov 19 '18 at 16:14


















          • thanks again @Psidom !
            – ToddT
            Nov 19 '18 at 16:14
















          thanks again @Psidom !
          – ToddT
          Nov 19 '18 at 16:14




          thanks again @Psidom !
          – ToddT
          Nov 19 '18 at 16:14


















          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.





          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375906%2fretrieve-index-of-just-one-element-in-v-for-loop%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

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]