Using Vue to implement a global editing function for all checkboxes and selects - dealing with object stickiness

Unique Ordering System

Check out the Codepen here!

Main Goal

The main objective is to develop a dynamic ordering system that caters to customer needs.

This involves uploading files, storing them as an array of objects, and generating a table with product details from those files.

When a user selects a product, an ajax request is made to retrieve all available options for that specific product.

If the "all" checkbox is enabled, the user should have the ability to modify all products and their options globally. Deselecting it will revert back to normal behavior.

The Challenge:

The v-model functionality works perfectly until checkboxes are involved. It seems like once checkboxes are used, the v-modelling sticks, and the options lose their independence.

Steps to Replicate:

  • Click on the "all" checkbox (found at the top left corner)
  • Select a product (first entry in the product list)
  • Choose an option (from the first product entry)
  • Deselect the "all" checkbox
  • Try modifying the options and observe how the order object updates for all items.

Data Overview:

There is a products array consisting of product objects.

An order array holds file keys along with associated product options—this is where the issue lies

Additionally, there's an options array that gets updated upon selecting a button, linking it to the respective file key.

"All" Checkbox Concerns:

The problem might stem from the method of product selection implemented as shown below:

checkboxAllHandler(checked) {
  if (checked) {
    this.files.forEach((file, index) => {
      this.selectedFiles.push(index)
    });
  
    const product = Object.assign({}, this.order['products'][this.getSelectedFile]);
    console.log(product);
    const order = Object.assign({}, this.order);

    this.selectedFiles.forEach(fileIndex => {
      order['products'][fileIndex] = product || {};
    });

    this.order = {};
    this.order = order;
  } else {
    this.selectedFiles = [];
  }
}

Any assistance provided in resolving this challenging issue would be greatly appreciated in advance. Thank you!

Answer â„–1

Initially, there is an issue with the absence of the :key property in the v-for loop. Consequently, all rows are considered identical - rectify this by changing the line to:

<tr v-for="(file, fileKey) in files" :key="file">

Furthermore, within your loop, each row is being assigned the same product, resulting in undesired behavior:

    const product = Object.assign({}, this.order['products'][this.getSelectedFile]);
...
    this.selectedFiles.forEach(fileIndex => {
      order['products'][fileIndex] = product || {};
    });

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

Managing various parameters within express routes

Currently, I am in the process of developing a website that utilizes Express and routing to manage HTTP requests. As part of this project, I am dynamically populating my HTML div elements using Handlebars: <div class="popup center" style="height: 15em ...

Is there a method to initiate a 'simple' action when dispatching an action in ngrx?

Here's the scenario I'm facing: When any of the actions listed below are dispatched, I need to update the saving property in the reducer to true. However, currently, I am not handling these actions in the reducer; instead, I handle them in my ef ...

Express Concurrency: Managing Multiple Tasks Simultaneously

Looking to create an API using Express that is capable of processing requests either through multithreading or multiprocessing. For example, the following API has a 5-second sleep before responding. If I make 3 quick calls to it, the first response will ta ...

How to retrieve an array from a JSON object with JavaScript

After receiving an object from the server, I am specifically looking to extract the array ITEMS. How can I achieve this? I attempted using array['items'] but it did not yield the expected result and returned undefined { "items": [ { ...

Vue Progress Bar service

When working with Angular, I typically utilize a dedicated class to manage the progress bar functionality. By intercepting HTTP requests and routing requests, including GraphQL requests like so: loading-indicator-service import { Injectable } from &apos ...

Tips for managing the sequence of chosen items

Currently, I am utilizing the react-dropdown-tree-select component in my project. I have a question regarding changing the order of selected items. The current default behavior is for the selected item order to match the data list order. However, I woul ...

Using Reactjs to Send Emails

Trying to incorporate the SmptJs API for email sending using JavaScript has been quite successful in a simple HTML setup. However, I am facing challenges when attempting to integrate it into a ReactJs component! The API documentation and link can be found ...

A pause of 5 seconds between every request in Node.js

Need Help with Delays in Node.js Request Queue I am facing an issue with my code that involves looping through more than 500,000 records in a database and requesting information from another server. I have managed to write all the necessary functions, but ...

Issue with uploading images in Vue/Laravel: Unable to successfully transfer images to Laravel backend

Having trouble with image uploads in Laravel. The images are showing as an empty array: { "photo": {}, "nid": {}, "address": "Dhaka", "upazila": 493, "emergency_contact": "01719123886", "blood": "A__(positive)" } However, in Vue, w ...

Unable to refresh the fullcalendar section following an ajax post click

Currently developing a calendar using fullcalendar. I have created an ajax button that retrieves events from another php page. The first click on the ajax button works fine, displaying a nice month calendar with events. However, my issue arises when I cl ...

Improving iframe functionality in AngularJS

I've been experimenting with AngularJS to dynamically update an iframe whenever a query is triggered. It works like this: a query is made, the embed link is fetched from the database, and then it's used in the iframe alongside the title and video ...

Is it possible for my node.js to become unresponsive when comparing lists?

In my node.js app, I have two lists - one retrieved from a database and the other created by listing file names on a server. Both lists contain approximately 750,000 strings each, and now I need to search for each string in one list within the other. As a ...

Setting up angular-cli project for rc5- Step by step guide

Trying to integrate angular-cli with angular 2 rc5 but facing challenges: The issue of 'Promise' not being found After attempting to install 'npm install -g angular-cli@webpack', typings did not get installed, resulting in WebStorm un ...

Generate a random number not found within the given array

Hopefully, I can explain this clearly. Imagine I have 8 boxes with the class .boxA, each containing a numeric value generated from JavaScript: <div class="tfooter"> <div class="boxA" id="bx3" value="3">3</div> <div class="box ...

The challenge lies in updating props using the `onchange` event in Vue.js 2

I am facing an issue with updating the data when using on-change from the select box. Initially, I can update the data by clicking a button or triggering the on-change event once. However, I encounter difficulties in updating the data multiple times throug ...

What methods can be used to test the functionality of bootstrap-vue toasts?

In order to confirm that our mistakes have been displayed in the bootstrap-vue toast messages, I need guidance on how to validate this during testing. My initial plan was to simulate 'this.$bvToast.toast', but so far I haven't found a suitab ...

terminate the express middleware and return a custom HTTP status code

Is it possible to use custom middleware to return a 404 or 401 error to the user and prevent other handlers from running? I tried implementing the following code: function SomeMiddleware(req, res, next) { if(user.notRealOrSomething) { throw new Htt ...

How to connect a form component object with a parent object in Vue3 using v-model and the Options API?

My inquiry is quite straightforward. I am exploring the official Vue documentation that delves into v-model arguments in relation to forms within a child component. Here is the code snippet I am referring to: (App.Vue) <script> import UserName from & ...

Conceal the div with ID "en" if the value matches $en

Looking for assistance with language settings on my page. I have a menu where I can select English, Croatian, or German. Below is the code to manage language changes: <?php class home_header_language { protected $_DBconn; ...

Verifying picture quality prior to transferring to a remote server

I am facing an issue with my image upload function to a remote server. The upload function works fine on its own, but when I integrate it into the size validation block, it stops working properly. <p> <input type="file" id="BtnBro ...