Only utilize v-model or bind when the button within the modal is clicked in vue

I'm facing an issue with pre-filling data in a Vue modal when the page loads. Currently, the modal is rendered and hidden, causing every row that creates a modal to already render a textarea and input that I wish to pass to a function on button click.

Is there a way for me to modify this behavior so that I only pass the textarea and hidden input to the props if the save button is clicked?

 @foreach($results as $k => $result)
    <tr class="" id="">
        <td>
            <a id="show-row-modal" @click="showModal = {{$k}}; getDetails('{{$result->contentID}}');">{{$result->number}}</a>
            <modal v-if="showModal==={{$k}}" @close="showModal = false">
            <h2 slot="header">{{$result->number}}-{{$result->name}}</h2>

            <div slot="body">
            <textarea style="width:100%; margin: 0 auto;" v-model="resultsContent">{{utf8_encode($result->content)}}</textarea>
            <input type="hidden" value='{$result->contentID}' v-model="existingCopyID" />
            <button>save</button>
            </div>
        </td>
    </tr>
    @endforeach


    <script type="text/x-template" id="row-modal-template">
      <transition name="rowModal">
        <div class="modal-mask">
          <div class="modal-wrapper">
            <div class="modal-container">
            <div class="uk-grid">
              <div class="modal-header uk-form-row uk-width-1-1">
                <slot name="header">
                  default header
                </slot>
              </div>

              <div class="modal-body uk-form-row uk-width-1-1">
                <slot name="body">
                  default body
                </slot>
              </div>

              </div>
            </div>
          </div>
        </div>
      </transition>
    </script>

     Vue.component('modal',{
    template: '#row-modal-template'
    })

    new Vue({
        el:'#app',
        data: { 
            showModal: false,
            existingCopyID: [''],
            resultsContent: [''],
        },

Answer №1

To ensure that input changes do not immediately update the bound state, consider using refs. This way, you can retrieve input values only when the save button is clicked:

<textarea style="width:100%; margin: 0 auto;" ref="resultsContent">{{utf8_encode($results->content)}}</textarea>
<input type="hidden" value='{$results->contentID}' ref="existingContentID" />

...

handleSaveClick() {
  // Access input values using this.$refs
  console.log(this.$refs.resultsContent.value);
  console.log(this.$refs.existingContentID.value);
}

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

Hidden content from Vue router view

My goal is to have the navigation pane overlaying the content of the page, but instead, it is being appended to the bottom where the end of the navigation drawer would be. I've experimented with different variations to display data using navigation dr ...

A Guide to Displaying HTTP Error Messages on the Angular Login Page

When encountering a form validation failure on my login page, I utilize ngMessage to display an error message. However, I now want this div to be displayed in the event of an HTTP 500 error. While I can retrieve the corresponding error message when an HTTP ...

Tips for including a permanent button at the bottom of a material ui dialog box

I want to implement a dialog popup in my react js application. When the user clicks on a button, the dialog should open up. Inside the dialog, there is a form with input fields. After the user fills out all the inputs, they can submit the information by cl ...

Is there a way to track and detect alterations to an element using JavaScript or jQuery

Can I detect the addition of a specific CSS class to an element without having to create a new event? ...

The VueJS Progressive Web App is displaying a Network Error message in my compact PWA. I am unable to access the login feature as

My PWA is functioning properly except for POST HTTP calls. When attempting to login on the first screen, I encounter a "Network Error" message. Curiously, this issue only occurs on the mobile app [Android], while it works flawlessly on Desktop/Laptop web b ...

How to handle users with disabled Javascript? Considering redirection to alternate sites for users with script disabled?

I've dedicated today to strategizing the best approach for revamping our company's website, taking into consideration that less than 1% of web users have JavaScript disabled. Our management team strongly believes in ensuring that our website rem ...

Unable to modify the hover color on the image or icon

After creating a circle icon with an image in the center, I wanted to make the image change colors on hover. The main focus of the icon is the circle itself. In my attempt to achieve this effect, I included the following code for the circle icon: .circle- ...

I am facing an issue with the Node.js MongoDB callback function. The code snippet runs perfectly on my laptop, but it fails to work on a different

On my Laptop, the code snippet below operates perfectly fine; however, it encounters issues on a different PC. // establishing connection with mongodb MongoClient.connect(url, function (err, db) { if (err) { winston.error('Error connecting ...

JS not functioning properly in specific pages causing display issues with page height set to 100%

I am facing an unusual issue where certain pages do not stretch to 100% page height in the middle section, causing the left-hand border to be incomplete. For example, on the 'Brentwood' site (please click on the 'Login' link in the top ...

Tips for concealing the left and right navigation elements depending on the first and last list items

How can I dynamically hide navigation buttons based on the first and last image in a slider? I created a slider using jQuery that shows 3 images out of the total number available. The functions moveRight() and moveLeft() are used to display a set of 3 im ...

Display the first item last in an *ngFor loop in Nativescript Angular

I'm facing some confusion with the sorting of an array in JavaScript. Although the index, last, and first seem to be correct, the result is not as expected. Versions @angular/core: 4.1.0 nativescript-angular: 3.1.3 typescript: 2.4.0 Expected 1234 ...

What is the reason behind the appearance of 'Cannot Get/' when trying to render pug?

Attempting to configure a basic Express server with a simple pug template. Could you kindly point out what I might be doing incorrectly in this setup? 'use strict'; //Require Express var express = require('express'); var app = expres ...

When using jQuery each method, it may return an [object Object]

Having an issue with the html variable displaying [object Object] instead of actual elements. Any suggestions on what I should change? var html = ''; $.each(data.response, function(index, value) { var tr = $('<tr>'); var ...

Implementing pagination in React: A step-by-step guide

I am fetching data from the GitHub API, specifically from here Although I have all the necessary data to display, I want to limit it so that only 20 repositories are shown per page. In addition, I prefer not to use any frameworks or plugins for this task ...

Why is it that my post request works in Postman but not in the browser, even though I'm following the same steps?

When using Postman to authenticate with my Passport endpoint, I am able to successfully post to my SQL database using a different endpoint. This includes uploading the file name, email, and user_id. However, when attempting the same process in the browser ...

Storing the blob received from an AJAX call into Azure Blob Storage may result in a corrupted image

When I send a PDF to my vendor's API, they return a .png file as a blob (note: see update 2 regarding the data type being returned). I want to store this in Azure Blob Storage. However, when using the code below, the uploaded file becomes corrupted. ...

IE8 experiencing issues with jQuery live click event functionality

I have this code snippet that is working perfectly fine in all browsers except for IE8. The #cal_popup_table element is dynamically added to the page. $("#cal_popup_table tbody tr td a").live('click', function() { $('.da ...

Angular 6 - detecting clicks outside of a menu

Currently, I am working on implementing a click event to close my aside menu. I have already created an example using jQuery, but I want to achieve the same result without using jQuery and without direct access to the 'menu' variable. Can someon ...

Cease the clicking action event

How do I terminate a mousedown function when the mouse is released? $('#manRun').mousedown(function(e3) { var manID = get_id(this); e3.preventDefault(); $(document).on('mousemove.moveMan', function(e2) { ...

What prevents certain scenarios from being encapsulated within a try/catch block?

Just attempted to handle ENOENT by using a naive approach like this: try { res.sendFile(path); } catch (e) { if (e.code === 'ENOENT') { res.send('placeholder'); } else { throw e; } } Unfortunately, this method is ineffectiv ...