No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Select with new-value in a loop

    Help
    1
    2
    393
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      blakeyuk last edited by

      Hi all,
      I’ve got a page with a series of selects in a loop, each of which I am using the new-value property to allow new entries to be created.

      I can get the form working, and the data is submitted, however, I need to get the index of the select from it’s parent loop, when the ‘add-new’ event function is called:

      <q-form @submit="onSubmit" class="q-gutter-md">
            <div v-if="questions.length">
              <div v-for="(question, index) in questions" :key="question.id" class="row">
                <div class="col">{{ question.text }} ({{ index }})</div>
                <div class="col">
                  <q-select v-model="model.questions[question.id]" :options="question.answers" use-input use-chips multiple label="" option-value="id" option-label="text" new-value-mode="add-unique" @new-value="createValue" />
                </div>
                <div class="col">
                </div>
              </div>
              <div>
                <q-btn label="Submit" type="submit" color="primary" />
              </div>
            </div>
            <div v-if="!questions.length">No questions found</div>
          </q-form>
      
      createValue(val, done) {
      
            ///////////////// HOW DO I GET THE SELECT INDEX HERE ?????
            done(val)
          },
      

      I tried just passing $event in the event @new-value=“createValue($event)” , but bizarrely that only passed the new value, not the normal event object.

      Any help would be MUCH appreciated!

      Regards,
      Andy

      1 Reply Last reply Reply Quote 0
      • B
        blakeyuk last edited by

        Ah, got it sorted thanks to this: https://forum.quasar-framework.org/topic/6135/passing-more-information-and-or-event-from-q-select-on-change-input/9

        Final solution:

        <q-form @submit="onSubmit" class="q-gutter-md">
              <div v-if="questions.length">
                <div v-for="question in questions" :key="question.id" class="row">
                  <div class="col">{{ question.text }}</div>
                  <div class="col">
                    <q-select v-model="model.questions[question.id]" :options="question.answers" use-input use-chips multiple label="" option-value="id" option-label="text" @add="add" @new-value="(value, done) => { createValue(value, done, question.id) }" />
        
                  </div>
                  <div class="col">
                  </div>
                </div>
                <div>
                  <q-btn label="Submit" type="submit" color="primary" />
                </div>
              </div>
              <div v-if="!questions.length">No questions found</div>
            </q-form>
        

        and

            createValue(val, done, questionId) {
                console.log("questionId", questionId)
                done(val)
            },
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post