The functionality of selecting all items in v-select does not result in saving all of them

I'm currently working on integrating a select all button into the v-select component of Vuetify. The issue I am facing is that even though I can use the button to select all options, when I attempt to save, not all items are saved. However, if I manually select each option one by one and then save, all items from the dropdown are successfully saved. Can someone please assist me in identifying the problem?

<template>
 <v-select
  :items="documents"
  v-model="user.versions"
  :closeOnSelect="true"
  multiple
  attach
  auto
  item-text='name'
  item-value='id'>
 </v-select>
 <v-btn class="red-button" @click='selectAll'>Select</v-btn>
 <v-btn class="red-save-btn" @click='submitDocuments'><i class="material-icons edit">save</i> Save</v-btn>
</template>

<script>
 export default {
  props: ['user'],
  data: function () {
      return {
       documents: [],
       versions: []
      }
  },
  methods: {
   selectAll (){
    this.user.versions = [...this.documents]
    },
   submitDocuments() {
        var that = this;
        this.$axios.put(`/my_account/users/${this.user.id}.json`, {user: this.user})
   }
 }
}
</script>

Answer №1

When attempting to directly modify a prop, you may encounter the following warning:

It is recommended to avoid directly changing a prop as its value will be overwritten whenever the parent component re-renders. Instead, consider using a data or computed property that depends on the prop's value.

If you wish to utilize v-model, you can implement a computed setter/getter method:


computed : {
  _user : {
     get () {
        return this.user
     },
     set (val) {
        this.$emit('change', val)
     }
   }
}

You can then bind the v-model in your v-select element to the computed property like so:

<v-select v-model="_user.versions">

For a practical demonstration, refer to this code snippet: https://codepen.io/ellisdod/pen/jOPeRyr?editable=true&editors=101

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modify the background of a Div element by selecting an alternate color palette

Here is my code that changes the background of a Div on select change from a dropdown. I believe there might be a more efficient way to achieve this. Can anyone provide recommendations? Thank you for taking a look. $(document).ready(function() { $(" ...

JavaScript utilizing a PHP variable

In my attempt to merge a PHP variable with JavaScript, I aim to access the "the_link_to_the_page_I_want". window.onload = function openWindow() { window.open('the_link_to_the_page_I_want', 'newwindow', config='height ...

Leverage ESlint for optimal code quality in your expressjs

Is there a way to use ESlint with Express while maintaining the no-unused-vars rule? After enabling ESlint, I am encountering the following issue: https://i.stack.imgur.com/7841z.png I am interested in disabling the no-unused-vars rule exclusively for e ...

The JavaScript array remains unaltered

I've got an express server set up with GET and POST routes. The initial state looks something like this: let orders = [ { sum: 0, purchases: [ { id: 1, contractId: ...

How can I prevent SweetAlert from automatically focusing when it first opens?

I recently integrated SweetAlert into my project and customized the buttons like this: swal("A wild Pikachu appeared! What do you want to do?", { buttons: { cancel: "Run away!", catch: { text: "Throw Pokéball!", value: "catch", ...

Is it possible for me to reconstruct the "reducer" each time the useReducer hook is rendered?

Here is an example taken from: https://reactjs.org/docs/hooks-reference.html#usereducer const initialState = {count: 0}; function reducer(state, action) { switch (action.type) { case 'increment': return {count: state.count + 1}; ...

What steps should I follow to ensure that the content for the back page is printed on the back page of a booklet when using paged.js?

In the case of a booklet printed from folded sheets, it is interesting to note that the number on the back page will always be divisible by 4. If the content does not have a multiple of 4 pages, then the back page will end up inside the booklet. For my cu ...

Showing the computation outcome on the identical page

I have implemented a table within my PHP code. In the second column of this table, it typically displays "---". However, once I click the submit button, the same page should now display the calculated result. Here is an example: <table> <tr>& ...

merge various useState functions for appending values to an array into a unified function in a React component

I am currently facing a challenge with code complexity. I have 8 arrays where I need to add items based on a button click. As of now, I have created 8 separate functions for each task. Is there a way to consolidate all these functions into one function tha ...

Vue @click event fails to trigger modal display

I'm currently building a Laravel SPA and utilizing Vue.js as the front end framework. I've encountered an issue that I'm struggling to resolve because, in my opinion, there's nothing wrong with my code. All the @click functions within m ...

Is the jQuery AJAX call using POST method being retrieved as $_GET?

Below is a snippet of code that I've successfully implemented: <script type="text/javascript"> $(document).ready(function() { // Initializing the table $('#table_1').tableDnD({ onDrop: function(table, row) { $.tab ...

Retrieving the internationalization (i18n) locale language from the Pinia store

I am attempting to retrieve the value of the i18n locale language from my pinia store, however, an error is occurring Uncaught Error: [ ...

methods for retrieving nested JSON data from an API endpoint

My data has been exported in JSON format { "count":79, "stories":{ "23658975":{ "title":"NOMINATIVO", "description":"BUSDRAGHI PIERGIORGIO", "updated_at":"2013-06-16T18:55:56+02:00", "created_at":"2013-06-16T18:39:06+02:00", "du ...

Ways to verify user authentication for navigating Vue routes

Working on a Single Page Application with Vue front-end, Express, and Parse (parse-platform) for back-end. After authenticating the user, I store their info in a session variable req.session.user = result; before sending it back to the client using res.sta ...

Vuex sending information to the component

My Vuex actions include an axios call return axios({ method: 'get', url: `/myurl`, }).then(function (response) { context.commit('value', response.data.data); }), When this is called in my component this. ...

Unit tests manipulating JavaScript functions to return undefined values

Currently, I am in the process of testing some JavaScript functions within a larger React application. These functions heavily utilize the module pattern, which leads me to believe that my misunderstanding lies within this pattern. The script I am testing ...

Is there a simple method to submit to a URL without relying on ajax?

When it comes to using jQuery, the $.ajax() function is typically used for POST requests to a URL. However, in my particular situation, I am unable to use this function. I need the client to send a POST request to a URL and have the server redirect the use ...

How can I update a dropdown menu depending on the selection made in another dropdown using Angular

I am trying to dynamically change the options in one dropdown based on the selection made in another dropdown. ts.file Countries: Array<any> = [ { name: '1st of the month', states: [ {name: '16th of the month&apos ...

Asynchronous retrieval of reference value from Firebase Firestore in ReactJS

Encountering a peculiar bug in TypeScript-JavaScript where I have a Model class in TypeScript and a ReactJS Component in JS. The issue arises when dealing with a list of Promo Objects, each containing a "_listCompte" property which holds a list of Compte O ...

Tips for resolving the issue of receiving a warning about passing "onClick" to a "<Link>" component with an `href` of `#` while having "legacyBehavior" enabled in Next.js

My current project is displaying a lot of warnings in the browser console and I'm unsure about the reasons behind it. The warnings include: "onClick" was passed to with href of /discovery/edit but "legacyBehavior" was set. The l ...