Different ways to implement the Vue search select feature in various form structures

I am facing an issue with showing select options of my product in multiple forms. Whenever I choose one option in one form, all the other select forms also change automatically.

How can I make each select form unique?

Here is what I have tried:

My select form

<tr v-for="(adddiagnosilom, index) in adddiagnosis" :key="adddiagnosilom.value">
    <td>{{ adddiagnosilom.value }}</td>
    <td>{{ adddiagnosilom.CodeID }}</td>
    <td>{{ adddiagnosilom.text }}</td>
    <td>
        <ListSelect :list="optionProduct"
             option-value="value"
             option-text="text"
             :selected-item="itemproduct[index]"
             placeholder="select product"
             @select="onSelectProduct">
        </ListSelect>
    </td>
    <td>
        <input class="form-control" placeholder="0" v-model="adddiagnosilom.ordered">
    </td>
    <td>
        <input class="form-control" placeholder="0" v-model="adddiagnosilom.price">
    </td>
    <td>{{ adddiagnosilom.sum = adddiagnosilom.ordered * adddiagnosilom.price }}</td>
</tr>

My variable

data() {
    return {
      adddiagnosis: {},
      itemproduct: [
        { value: '', text: '' }
     ],
    }
}

My select method

onSelectProduct (itemproduct) {
    this.itemproduct = itemproduct
},

Here is the screenshot https://i.sstatic.net/Yg2xB.jpg

Currently, all select options change when one is modified. What I want to achieve is to only change the select form that I am currently modifying, not affect all of them.

Answer №1

To transform itemproduct into an array, link it to itemproduct[index] rather than just itemproduct. This way, each select box value will be stored in a separate index within the array.

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

javascript for each and every textarea

I am looking to apply my JavaScript code to all the Textarea elements on my page. $_PAGE->addJSOnLoad(" $('.textarea').each(function() { $(this).keyup(function() { var characterCount = $(this).val().length; var mes ...

Use JavaScript to convert only the initial letter to uppercase

Once again, I am in the process of learning! Apologies for the simple questions, but learning is key... Attempting to implement a trick I found online to change all letters to uppercase, I am now trying to adjust it to only capitalize the first letters. T ...

Can files in a directory be listed using JavaScript without the need for HTML tags?

Currently, I am exploring ways to automate an Angular application using Protractor. During this process, I encountered a situation where I needed to retrieve a list of all the files within a specific folder. In Java, I am aware that we can accomplish this ...

Sorting the table: the parser for the table.config[c] is not defined

I've been struggling with the tablesorter plugin, as it doesn't seem to be functioning properly in sorting the table. Can someone please assist me? I've been trying to solve this issue for two days now. Here is the error: table.config.pars ...

How to display a minimalist white dot in three.js

I am currently working with THREE.WebGLRenderer and I have a requirement to display multiple white dots of the same size at specific locations in 3D space. Is it recommended to use sprites, calculate the 2D screen coordinates, and utilize SpriteMaterial w ...

Utilizing $asyncValidators in angularjs to implement error messages in the HTML: A guide

This is my first major form with validations and more. I've set up a Registration form and I'm utilizing ng-messages for validation. The issue arises when I have to check the username, whether it already exists in the JSON server we are using or ...

When clicking to open the md-select on Angular Material 1.1.0, an unwanted [object object] is being appended

Every time I try to open the md-select input, an [object Object] (string) is added to the body tag. Click here to see the md-select input After clicking the md-select once, this is how the body looks ...

Retrieving the previous value using JQuery's onChange event

Is there a way to retrieve the initial quantity value before it is changed with the onChange function in this code snippet? I'm encountering issues with the CSS while using this setup for an input box. You can view the problematic CSS here. Updating ...

Limit the selection of 'pickable' attributes following selections in the picking function (TypeScript)

In the codebase I'm working on, I recently added a useful util function: const pick = <T extends object, P extends keyof T, R = Pick<T,P>>( obj: T, keys: P[] ): R => { if (!obj) return {} as R return keys.reduce((acc, key) => { re ...

Parse a string containing a selection of markdown by using regular expressions for tokenization

I need to tokenize a string using a regular expression that consists of markdown formatting. Specifically, bold text is denoted by **text** and italic text is denoted by _text_. To tokenize the string "a _b_ c **d** _e", it should be split into ['a & ...

What could be causing the PAGE CSS to malfunction?

I am looking to export HTML text as a word document with A4 size and portrait orientation. My JavaScript currently allows me to export the text, but it appears like a webpage format rather than in A4 or portrait mode. I have tried adding @page CSS styling ...

Is it important that the end date does not exceed the start date?

In my request, the end date cannot be later than the start date. For example, if the start date is 24/4/2017 and the end date is 23/4/2017, the search function should be disabled for the calendar date 23/4/2017. Only dates from 24/4/2017 onwards should be ...

Sending SQL queries with multiple selections, each containing three values for every option

I am faced with a challenging question that will require me to dedicate long hours towards solving it and finding a solution. Imagine I have a multiple select element with various options, each consisting of 3 values: One value for the language name One ...

Ensuring Form Validity with jQuery for Exclusive Radio Buttons

How can I display an error message when a radio button value is not equal to a specific value? I have a series of yes/no questions and want to show disclaimers under each set of buttons if the value provided is null or different from what is required. Most ...

Mastering the use of getText() in Protractor with Page Object Model in Javascript

Having trouble retrieving specific values from my page object. The getText() method is returning the entire object instead of just the text, likely due to it being a Promise. I can provide my code if necessary, but I'm aiming to achieve something sim ...

The issue of Jquery selectors not functioning properly when used with variables

Currently working on a script in the console that aims to extract and display the user's chat nickname. Initially, we will attempt to achieve this by copying and pasting paths: We inspect the user's name in the Chrome console and copy its selec ...

interaction between modernizr and ajax causing loading issues

I am currently utilizing modernizr.js and a customized ajax function on my page to refresh the content every x seconds. Below is the snippet of code for the functions being triggered. function reloadSlides() { jQuery.ajax({ url: document.locat ...

Error: Can't compile - Accordion controller is necessary

Encountered the following error in the console while using angular-bootstrap ui. My setup includes angular 1.2.6, bootstrap 3.0, and angular-bootstrap 0.10.0. Error: [$compile:ctreq] Controller 'accordion', required by directive 'accordionG ...

Issue with Vue: Calling method instantly when using :mouseover in v-for within a component

Whenever I try to incorporate :mouseover in a v-for loop within the <component>, I encounter an issue. The method assigned to the :mouseover event is triggered for each element, rather than just for the hovered elements. <Single-technology ...

Error: Unable to access the 'center' property of an undefined value in the three.module.js file

I started delving into coding a few months back, with my focus on mastering three.js/react. Currently, I am engrossed in a tutorial located at [https://redstapler.co/three-js-realistic-rain-tutorial/], where I aim to create a lifelike rain background. The ...