Ways to modify input value based on another input in VueJS

Two sets of text boxes are displayed in a grid format, which can be viewed here.

The objective is for users to fill out the top boxes and have the values automatically update as they fill out the corresponding bottom boxes. For example, if you input 100 in the first box at the top, then 75 in the first box at the bottom, the value in the top box should adjust to 25.

I attempted to use onchange() but didn't succeed. The v-model attribute seems to present issues with its two-way binding feature, which is understandable. Any assistance on this matter would be greatly appreciated.

Below is the HTML code that generates the input boxes:

> <form v-on:submit.prevent="addNewTask">
    <table>
      <thead>
        <tr>
          <th></th>
          <th v-for="(column, columnIndex) in columns" :key="columnIndex">{{column}}</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(record, rowIndex) in records" :key="rowIndex">
          <td>{{record.row}}</td>
          <td v-for="(detail, index) in record.details" :key="index">
              <input type="text" v-model="detail.value">
          </td>
        </tr>
      </tbody>
    </table>
    <br><br>
    <table>
      <thead>
        <tr>
          <th></th>
        <th v-for="(columnS, columnIndexS) in columns_Spend" :key="columnIndexS">{{columnS}}</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(recordS, rowIndexS) in records_Spend" :key="rowIndexS">
          <td>{{recordS.rowS}}</td>
          <td v-for="(detailS, indexS) in recordS.details_Spend" :key="indexS">
              <input type="text" v-model="detailS.value_Spend">
          </td>
        </tr>
      </tbody>
    </table>
    <br><br>
    <button v-if="this.isEdit == false" type="submit" class="btn btn-success btn-block mt-3">
      Submit
    </button>

Answer №1

To begin, break down the <td> elements into individual components and send their values to the parent component when there is a change in input. Next, create a function to compute and assign the remaining value for the "other" box child component (which should be stored in an Array - the correct element must be located within that Array using the method). The modified array will automatically update the other child component since it is connected to the property.

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

Error encountered when attempting to pass a custom component as a prop in VueJS that is undefined

Can you please clarify why Vue is indicating that Unknown custom element: <MyComponent> - did you register the component correctly? is an issue in this code snippet: const CustomComponent = Vue.component('CustomComponent', { template: &a ...

What is the best way to display the time of a post update similar to the style of

I am currently working on creating a notification deck. Instead of displaying the time when a notification was received, I aim to show the time that has passed since its arrival similar to how Twitter and Facebook do it with formats like "32m" or "1 hour a ...

A node module designed to efficiently convert multiple TIFF images into a single multipage TIFF document

Looking to combine several tiff images into a single file using nodejs/javascript. Is there a method to create a single tiff file with multiple pages from separate tiff images in nodejs? Can we convert a multi-page pdf into one tiff image using nodejs? ...

Encountering a problem with configuring webpack's CommonsChunkPlugin for multiple entry points

entry: { page1: '~/page1', page2: '~/page2', page3: '~/page3', lib: ['date-fns', 'lodash'], vendor: ['vue', 'vuex', 'vue-router'] }, new webpack.optimize.C ...

Implementing the jQuery datepicker in Angular.js can be challenging

I recently started learning Angular.js and have been working on a web application using this framework. I am now looking to include a datepicker in one of my forms. Below is the code snippet that I have implemented: app.js myapp.directive(& ...

Creating a pattern for values ranging from 18 to 99, including leading zeros, using regular expressions

Looking for a Regular Expression that matches numbers from 018 to 099, inclusive. The numbers must range between 18 and 99, and include a leading zero for values less than 100. ...

Issue with Jquery Slider Showing Empty Slide

Currently addressing issues with the slider on my site, which utilizes SlidesJS at . There seems to be a problem where it shows a blank slide inexplicably. After investigating, I noticed that a list element is being added to the pagination class, but I can ...

What is the proper method for setting up handlers in functional React components?

My knowledge of JavaScript tells me that there are three different ways to define functions. Let's take a look at them: 1. Declaration function handleEvent(e) {} 2. Assignment var handleEvent = function(e) {} 3. Arrow var handleEvent = (e) => ...

What is the best way to display a unique image in a div based on the size of the

Being new to web design, I have a question about creating a webpage with a large image in the center like on GitHub's Windows page. How can I work with the image inside that particular div or area based on different screen sizes? Is it possible to mak ...

Activate search bar by clicking on it

I am currently attempting a basic jQuery example to expand a search bar on mouse click, but for some reason, my code is not working as expected. I have a simple jQuery function to display the input field when the button with the class "expand" is clicked, ...

What is the best way to iterate through this JSON data and add it to a div in an HTML document?

Here is the structure of my JSON: { "content": [ { "title": "'I need some rest'", "description": "Descript One", "link": "http://www.google.com/?id=90#hhjjhjC-RSS", "guid": "http://www.google ...

Extracting Data from JSON Using Vue.js

I am facing an issue with extracting data from a JSON file using Vue.js. Below is the HTML and JSON data along with the script. Any help would be appreciated. <!DOCTYPE html> <html> <head> <title>Vu ...

Troubleshooting Axios Error while Sending Data in MERN Stack Application

In my development setup, I'm testing model validation specifically for the length of a name variable. The front-end is configured at http://localhost:3000/ using React + axios, while the back-end utilizes express + node. To enable communication betwe ...

Consolidate radio group in Vuetify platform

I'm having trouble centering the v-radio-group. Here's my current setup: <v-container grid-list-md text-xs-center> <v-form ref="form"> <div v-if="question.question_type == 'YESNO' "> <v-radio-group ...

Setting up HMR for a Vue.js app can be a bit tricky, especially when trying to run it locally

1. The Caddy version I am using (caddy -version): v2.0.0-beta.13 h1:QL0JAepFvLVtOatABqniuDRQ4HmtvWuuSWZW24qVVtk= 2. How I execute Caddy: a. Environment details: I have the caddy server static binary running on macOS Mojave - 10.14.6, and added the bina ...

Navigating through multiple layers of React refs can be achieved using a technique called travers

Hey there, I'm currently working on extracting all the a tags from within the #header-nav section. const HeaderNav = (props) => { // setState const $target = useRef(null); const $component = $target.current.querySelectorAll('a'); return ...

Having trouble converting a JSON array into a JavaScript array upon creation

I have encountered this question multiple times before and despite trying various solutions, I have not been able to find success. Summary: My goal is to retrieve the array from the classes.json file and then assign the data in the variable classes from d ...

Testing infinite scrolling with the help of protractor

It seems like the infinite scrolling feature in ng-grid is not exactly infinite, but it's the closest comparison I could come up with for what I am observing. In our application, we are using ng-grid to display data in a table with approximately 170 ...

Make sure to switch up the font color with each new use of the "append" function

Currently, on my page, I am using the append function to add a new line of text (".newText") every 5 seconds. This is my current implementation: var fontColors var randomColor $(function(){ fontColors = ['red','orange','yello ...

WebStorm fails to identify Vue Material Components' HTML tags

When working with VueMaterial in WebStorm, I've encountered an issue where only the <md-list-item> HTML tag is being recognized while others are not listed in the pop-up. This results in unknown HTML tag warnings when using them. https://i.ssta ...