Display or conceal a text field in Vue 2/Vuetify 1.5 depending on whether a checkbox is selected, with the possibility of duplicated

I've created a product checkbox selection feature that dynamically shows or hides text fields based on the user's selection.

Unfortunately, there is a glitch in the system where selecting the second item causes duplication of text fields from the first item and so on.

If you want to take a look at the code, you can visit it here.

The technologies used are Vue 2 and an outdated version of Vuetify - 1.5

On the HTML side:

<v-container grid-list-lg>
    <v-layout row wrap>
      <v-flex xs12>
        <div v-for="(item, index) of products" :key="index">
        <v-checkbox 
          hide-details
          v-model="selectedProducts"
          :label="item.name"
          :value="item.name"
          @change="showFields()"
        >
        </v-checkbox>
      </div>
      </v-flex>
    </v-layout>
    <v-layout row wrap v-for="(product, index) of selectedProducts" :key="index">
      <v-flex xs12>
        <h4>{{product}}</h4>
      </v-flex>
      <v-flex xs12 v-for="(item, index) of rowItems" :key="index">
        <v-text-field
          label="Price"
          v-model="item.price"
        ></v-text-field>
      </v-flex>
    </v-layout>
  </v-container>

On the JS side:

new Vue({
  el: '#app',
  data() {
    return {
      products: [
        {
          name: 'Item A',
          id: 1,
          price: 10
        },
        {
          name: 'Item B',
          id: 2,
          price: 20
        },
        {
          name: 'Item C',
          id: 3,
          price: 30
        },
      ],
      rowItems: {},
      selectedProducts: []
    }
  },
    methods: {
    showFields(){
      for (let item of this.selectedProducts){
        this.rowItems[item] = [{
          price: ''
        }]
      }
    }
    }
})

Answer №1

Issue Resolved!

All I needed to do was pass the product within the rowItems array.

Updated solution:

<v-flex xs12 v-for="(item, index) of rowItems" :key="index">

Changed to:

<v-flex xs12 v-for="(item, index) of rowItems[product]" :key="index">

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

How to Disable a Button with JavaScript in a Vue.js Application Without Using jQuery

I'm currently in the process of transitioning old jQuery code to JavaScript for a Vue.js application. function DisableSubmit() { submitButton.prop('disabled', true); submitButton.attr('data-enabled-value', submitButton.val ...

What are the best ways to conceptualize the benefits of WebRTC?

I encountered a peculiar issue with the abstraction of the WebRTC offer generation process. It appears that the incoming ice candidates fail to reach the null candidate. While I have been able to generate offers successfully using similar code in the past, ...

What could be causing the Gruntfile to throw an error?

Getting an unexpected error while trying to run grunt $ grunt Loading "Gruntfile.js" tasks...ERROR >> SyntaxError: Unexpected token : Warning: Task "default" not found. Use --force to continue. Execution terminated due to warnings. Here is my ...

Looking for the temporary folder created by the nodejs filesystem?

After encountering path issues with writing values from a textarea to a file using fs, I turned to stackoverflow and discovered that the path should be a tmp folder. Following this advice, the terminal indicated success with the process. However, now I am ...

The ul cannot be hidden if there are no li elements within it

Currently, I am attempting to hide the unordered list (ul) on a specific page using AJAX due to certain sections of the site being Ajax-based. <ul class="sub-nav-20-m" id="filtersList_m"> </ul> Below is the code that I hav ...

What could be the reason for encountering TypeScript within the Vue.js source code?

While exploring the vue.js source code, I stumbled upon some unfamiliar syntax that turned out to be TypeScript after further investigation. What baffled me was finding this TypeScript syntax within a ".js" file, when my understanding is that TypeScript ...

Ways to generate multiple void components side by side using React

What is the most efficient method for creating multiple empty inline elements using React in a declarative manner? Suppose I need 8 empty divs, I tried the following approach but it didn't work. Is there a more effective way? render() { return ( ...

What is the best way to extract a specific year and month from a date in a datatable using

My dataset includes performance scores of employees across various construction sites. For instance, on 2020-03-15, ALI TAHIRI was at the IHJAMN site. I need to filter this dataset by year and month. If I input 2020 for the year and 03 for the month, the d ...

Setting up a Progressive Web App installation feature with a built-in delay from a

I have integrated a v-dialog component that shows up when my webapp loads and is utilized for installing the PWA: <template> <div> <v-dialog v-model="popupAndroid" max-width="80%" ...

React app's compilation is failing due to non-compliant ES5 code generation of the abab module, resulting in errors on IE

Can anyone explain why a create-react-app project using TypeScript and configured to generate ES5 code is not functioning on IE11 due to the "atob" function from the 'abab' package not being compiled into ES5 compliant code? module.exports = { ...

Resetting the CSS for an input field: a step-by-step guide

My situation involves having a global CSS style set for text type inputs, such as: input[type=text] { padding:10px; width:100px; //and many more } Now, I am incorporating a plugin called colorpicker into a specific div. This plugin generates some input e ...

What is the process for programmatically importing a module into the local scope in Node.js?

The coding environment is using a browser and the bundle tool being used is webpack. In my router.js file, I have the following code: import foo from './views/foo.vue' import bar from './views/bar.vue' import zoo from './views/zoo. ...

Can you clarify the semver meaning of the >= operator and what is the highest version it permits?

It's commonly known that when using symbols like ^, it represents anything up to the next major version, and ~ means only patches. However, there seems to be a lack of clarity regarding what the maximum version is when utilizing >=. So, how should ...

Has xlink:href become outdated for svg <image> elements?

In the realm of SVG attributes, it is noted by MDN xlink:href that href should be used over xlink:href. Interestingly, on the svg example page, last revised on July 6, 2017, the attribute utilized in the given example is xlink:href. The question arises: ...

Error encountered with $ref during execution of nextTick() in Vue.js

I have implemented an eventListener to retrieve the scrollHeight of my 2 elements - h1 and wrap. The issue I am facing is that upon mounting, they are displayed as undefined even though I am using nextTick. Only after a user resizes the window do they dis ...

Show blob file as a PDF document in a popup or dialog box using HTML and TypeScript

I am currently working on integrating TypeScript and HTML to showcase the result of a webservice call as a PDF in a popup/dialog within the same page. While I can successfully open the PDF in a new tab using the window.open(url) method, I'm encounter ...

Ways to verify if a firebase timestamp surpasses the present date

Would you help me with comparing a timestamp field with the current date using JavaScript? This is what I have tried so far: // Initialize an empty array to store documents let myDocs = []; // Call the getDocs function and handle the response await getDo ...

Tips for maintaining the persistent state of tabs in a React.js application

I have created dynamic tabs using an array list, including nested tabs within those tabs. You can view the live sandbox link here: For the sandbox code and preview, visit: https://codesandbox.io/s/black-glade-phs69 The setup consists of 3 main tabs ...

There seems to be a glitch in the AJAX code

I am currently working on a project that involves displaying categories and subcategories of products on a webpage. When users click on either a category or a subcategory, AJAX is used to send the selected item to a php script which then generates HTML cod ...

Generate steps using Material UI/React Stepper to create organized pages (similar to Table Pagination)

As I venture into using Material UI along with React, my goal is to create organized "pages" consisting of steps in sets of four for a specific process. My initial attempt displayed all 10 steps on a single view, despite having the pagination correctly ca ...