The issue of two-way binding not functioning as expected specifically in the context of table rows

Currently, I have two inputs named col and row that can be adjusted to correspond with the columns and rows of a table.

I would like to view and modify the content of this table. I am utilizing a v-model to update my data based on the rows and columns inputted, but when integrating this into my v-for loop for the table, it does not automatically update.

The issue lies in the fact that the table is not being updated as intended.

This is the code snippet I am working with:

<div class="col-md-2">
    <input type="number" min="1" v-model="table.rows" class="form-control" id="rows">
</div>
<label for="columns" class="control-label col-md-1">columns:</label>
<div class="col-md-2">
    <input type="number" min="1" v-model="table.cols" class="form-control" id="cols">
</div>

<table class="table">
    <tbody  v-for="row in table.rows">
        <tr>
            <td contenteditable="true">John</td>
        </tr>       
    </tbody>
</table>

data() {
    return {
        table: {
            rows: 1,
            cols: 1,
            key: "Table",
            tableStyle: 1,
        },
        insert: 1,
    }
}

Any assistance or guidance would be greatly appreciated.

Answer №1

The data table remains stagnant as the text field is not connected to any model.

To resolve this issue, you must incorporate an @input event and adjust the model accordingly when triggered

<table class="table">
  <tbody  v-for="row in table.rows">
    <tr>
        <td contenteditable="true" @input="updateContent($event)">John</td>
    </tr>       
  </tbody>
</table>

data() {
    return {
        table: {
            rows: 1,
            cols: 1,
            key: "Table",
            tableStyle: 1,
            text: 'Default text'
        },
        insert: 1,
    }
},
methods: {
  updateContent (evt){
    //obtain the text
    const text = evt.srcElement.innerText;
    //modify the model
    this.table.text = text
  }
}

It's important to note that this modification would impact the entire table. To customize each row individually, you can transform table.row into a more intricate object with text, allowing for specific adjustments per row

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

Pattern matching for spaces and quotation marks

Despite reading several tutorials on regular expressions, I am still struggling to create the exact expression I need. I have an onblur function that performs the following actions... var x = $("#outputpathid").val(); var testwhitespace = new RegExp ...

What are some superior methods for determining the validity of a control in JavaScript?

Is there a way to determine the validity of a control in JavaScript within Asp.Net using a client-side API? Specifically, I am looking for a function that can check if a control is valid based on attached validators. For example, if a textbox has 2 validat ...

Inquiries regarding real-time alerts and notifications

Just curious, I am wondering about the creation of those notifications/alerts (for example on platforms like twitchalerts, commonly used by livestreamers). Are they typically coded in JavaScript/AJAX or another language? Is there a specific framework for ...

Ensuring Next.js doesn't create specific files at certain paths

Currently in the process of developing a custom e-commerce extension using Node.js, Koa, React, and Next.js for various platforms like Shopify and BigCommerce. Within the codebase, I'm faced with the challenge of handling URL methods that should stri ...

Error: Cloudant encountered a problem processing your request

Why is my attempt to upload JSON objects into a Cloudant database resulting in a "400 bad request" error? pos = { 'lat': position.coords.latitude, 'long' : position.coords.longitude }; $.ajax({ type: "POST", ...

Patience is key when using JavaScript

I have a JavaScript function that is responsible for updating my data. When the user clicks multiple times, I need to wait for the second click until the first one has finished processing, and so on. $scope.isLastUpdateFinished = true; $ ...

Incorporating a swisstopo map from an external source into an Angular

I am looking to integrate a swisstopo map into my angular 8 app. As I am new to angular, I am unsure how to include this example in my component: I have tried adding the script link to my index.html file and it loads successfully. However, I am confused a ...

Receiving a JSON object in response after sending data to a server using JavaScript

I am facing an issue with passing an email and password on login click to a database using PHP. After testing the email and password combination, PHP sends back a JSON object. While I have verified that the PHP code is functioning correctly and returns a J ...

Double submission issue with Angular form (multiple ajax requests)

My controller seems to be causing a form submission issue in AngularJS where the form is being submitted twice via a get request. Upon checking my database and the console network tab, I noticed that two submissions are logged, with the first submission sh ...

Converting JavaScript CanvasRenderingContext2D states array into a serialized format

Looking for a way to serialize a canvas' state in order to save it to a database for later restoration. Want to store the data as an object rather than a bitmap file. I've tried using .save() and .restore() on the context object, but they only m ...

What is the best way to create a shaking image animation using React Native?

I am trying to create a shaking image animation in React Native when a TouchableOpacity is pressed. So far, I have implemented an animated image with the following code: const backgroundImage = require('./components/images/baby-sleep.jpg') cla ...

The 'api' property is not found within the 'MyService' type declaration

Currently, I am working on a tutorial where we are building an Angular service to send emails from a form using the Mailthis Email API. In the code for the service, I encountered an error related to the 'api' variable that states "Property ' ...

PHP loop causing malfunction in jQuery Tooltip feature

I am trying to enhance my website with tool-tips, and I found this useful code snippet at In order to create table rows <tr>, I have implemented a while loop. The structure of my tool-tip <div> is as follows: <td class="maandgem">&e ...

Ways to superimpose images

Everything seems to be functioning correctly in my code, but I would like the output images to overlap slightly. This could possibly be achieved using margins, padding, or some other script. Additionally, is there a way to incorporate z-index so that the ...

Show a toast message and reset the form upon submission

Here I have created a contact form using HTML, CSS, and JavaScript. However, I'm facing an issue where the form redirects me to a page displaying the submitted details after clicking the submit button. I want to display a toast message instead and res ...

Implementing Button Activation and Deactivation Upon Checkbox Selection in JQuery

When a single checkbox is selected, the Edit and Delete buttons are enabled while the Add button is disabled. If two or more checkboxes are selected, the Delete button is enabled while the Add and Edit buttons are disabled. This is my HTML code: < ...

Discover the secret to opening two JPG files on YouTube using just one URL!

I was curious about the way YouTube thumbnails function. Here is an example thumbnail from a random YouTube video. There is an hqdefault.jpg in the URL, followed by some variables that indicate the size. If we remove or change these variables, a larger im ...

Personalized labels for your JQuery Mobile sliders

Struggling to make this work correctly, I aim to introduce tick marks and custom labels into jQuery Mobile's slider widget. My goal is to add tick markers at 0, 25, 50, 75, and 100 with a unique string above each tick. Additionally, I want these label ...

What is the best way to refresh jCarousel following the loading of AJAX content?

After purchasing a custom jCarousel JavaScript (available at http://pastebin.com/BwsVpNjr), I encountered an issue when trying to load content with AJAX. The carousel breaks because it is unable to detect the width or height. Is there a way to have jCarous ...

Executing javascript after an AJAX call within an on() method: Tips and tricks

I am struggling to make a $.ajax() call within a function triggered by the .on() method, in order to execute a script on a .click() event after updating newly appended data. I have tried numerous times to troubleshoot, but I can't seem to pinpoint the ...