Using the JS confirm function to switch the Vuetify checkbox in a Vue 2 application

It's been a real struggle trying to figure out this issue. I have a v-dialog that contains a checkbox. When the checkbox is clicked, a confirm() method is triggered to open a dialog in the browser to confirm the selection.

After confirming, the checkbox doesn't change visually, but the value of 'override' does. Clicking it again flips the 'override' value, causing confusion.

If 'cancel' is clicked, no changes occur.

I'm feeling quite lost at the moment and have been searching for solutions, coming across the idea of using click.native.

Previously, without the click.native.capture, no attempt to stop the action was made. I believe the solution lies in handling the stop request properly.

<v-checkbox
  ref="checkbox"
  dense
  :value="override"
  @click.native.capture="showConfirmationDialog($event)"
  class="pa-0 pl-5 ma-0 mt-3"
  label="Manually apply sale Price. WARNING: Will turn off auto updates."
></v-checkbox>

and the method:

showConfirmationDialog(event) {
  if (!this.override) {
    const result = confirm(
      'The action you are requesting will remove this product from automatic payment adjustments and information. You will need to re-apply the item in order to turn this back on. Are you sure you wish to continue?'
    );

    if (result) {
      this.override = true;
    } else {
      event.preventDefault();
      event.stopPropagation();
    }
  } else {
    this.override = false;
  }
}

Answer №1

If you utilize the v-model and promptly reset the value to false on the next UI update using nextTick if the result is false, you can seamlessly handle the situation without conflicting with Vuetify. This approach allows you to wait for v-checkbox to complete its operation before correcting the value. You can also opt for the standard @click method.

<template>
  <div>
    <v-checkbox
      ref="checkbox"
      dense
      v-model="override"
      @click="showConfirmationDialog"
      class="pa-0 pl-5 ma-0 mt-3"
      label="Manually apply sale Price. WARNING: Will turn off auto updates."
    ></v-checkbox>
  </div>
</template>
showConfirmationDialog() {
  if (this.override) {
    const result = confirm(
      'The action you are requesting will remove this product from automatic payment adjustments and information. You will need to re-apply the item in order to turn this back on. Are you sure you wish to continue?'
    );

    if (result) {
      this.override = true;
    } else {
      this.$nextTick(() => {
        this.override = false;
      });
    }
  } else {
    this.override = false;
  }
}

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

Is there a way for me to delay sending an immediate response until the asynchronous loop has completed?

Currently trying to implement something similar to the code snippet below. I suspect that the issue lies within the asynchronous call as it seems like the response I am getting is always an empty array, despite the API returning data. As a beginner in th ...

Navigate the div with arrow keys

Looking for an answer similar to this SO post on moving a div with arrow keys, could a simple and clear 'no' be sufficient: Is it possible to turn an overflowing div into a "default scroll target" that responds to arrow-up/down/page-down/space k ...

Javascript tells the time difference between 1 minute and 1 minutes. A timer is set up to notify when the time is

self.calculateMessageTime = function calculateMessageTime(receiveDate){ var dateReceived = Date.parse(receiveDate); var now = new Date(); now = Date.now(); // in seconds var difference = Math.abs(dateReceived - now)/1000; if(differ ...

If the iframe's CSS source is updated, the parent's CSS source will also change

I'm currently working on a unique school project that involves creating multiple CSS styles for different views. <link rel="stylesheet" type="text/css" href="css/main.css" title="main" media="screen"> <link rel="stylesheet" type="text/css" h ...

The ForbiddenError has struck again, this time wreaking havoc in the realms of Node.js, Express.js

I am currently adapting this GitHub sample application to utilize Express instead of KOA. However, I am encountering an Access Denied issue when the / route in Express attempts to load the index.html. What specific modifications are required in the code be ...

Is there a way to automatically play videos without any audio?

Is there a way for my video to automatically start playing when the page loads, without sound? I want it to function similar to the video on this webpage: . I've experimented with various jQuery, JavaScript, and CSS techniques from online resources, ...

Writing a CSV file to AWS S3 proves to be unsuccessful

I have been working with TypeScript code that successfully writes a CSV file to AWS S3 when running locally. However, I have recently encountered an error message: s3 upload error unsupported body payload object NOTES: The code is not passing creden ...

Is it advisable to combine ng-change with ng-blur in AngularJS?

Seeking clarification on the correct usage of AngularJS's ng-change and ng-blur from an expert. Specifically, when updating a form value. In the code snippet below, I have a dropdown where I would like to trigger overrideBusinessDec() when the user ...

Tallying the number of messages on Facebook

Greetings everyone! I have been utilizing the Facebook JS SDK to retrieve the number of messages sent. Below is the code snippet: <script> function statusChangeCallback(response) { console.log('statusChangeCallback'); console.log ...

Using jQuery, we can replace all `<span>` elements with `<img>` elements and then verify if the images have been successfully loaded

Similar Inquiry: jQuery check if image is loaded I find myself in a scenario where the following HTML structure is utilized: <div class="image"> <img class="" src="content-images/1.jpg"> <span class="slide" rel="content-images/ ...

Guide on obtaining an obscure style guideline in MS Edge using JavaScript

If you are looking to utilize the object-fit CSS rule, keep in mind that it is not supported in MSIE and MS Edge Browsers. While there are polyfills available for IE, none of them seem to work in Edge from my experience. For instance, the polyfill fitie b ...

Mastering the art of iterating through arrays using node.js request()

After transitioning from passing single values to multiple values in my node API, I encountered an issue where the API no longer responded. Here is an example of single values for fields: tracking: "123", // Only one tracking number carrier: "usps" // On ...

Locate a JQuery element within another JQuery element

Apologies for my poor grasp of English. I am working with HTML and JavaScript. <noindex> <h1>This is h1 in noindex</h1> <div> <h1>This is h1 in noindex and in div</h1> <div> <h1>This is h1 in noindex a ...

unable to configure socket.io to start listening on IPv4 address

While setting up IPV4 in Socket.IO, I encountered the following error: /var/www/js/AndroRAT/node_modules/socket.io/lib/index.js:279 opts.path = opts.path || this.path(); ^ TypeError: Cannot create property 'path' on string '0.0.0 ...

Should one consider building a web application by relying on browser AJAX requests a sound practice?

When developing a standard MVC web application, is it acceptable to rely heavily on ajax calls for rendering content? For instance, looking at Facebook as an example, they dynamically load a majority of their content. Should we emulate this strategy? What ...

Creating an uncomplicated search bar that dynamically adjusts values based on its function

Summing it up, there is a div situated within my app.component.html: <div class="col-lg-6 search-div"> <div class="input-group"> <input type="text" class="form-control" placeholder="Search for..."> <span class="input-group-b ...

Permanently dismiss Bootstrap 4 alert using a cookie

Recently, I came across a bootstrap 4 alert that I found quite useful. Here is the code snippet for it: <div class="alert alert-warning alert-dismissible fade show" role="alert"> <button type="button" class="clo ...

Alternating row colors using CSS zebra striping after parsing XML with jQuery

After successfully parsing XML data into a table, I encountered an issue with applying zebra stripe styling to the additional rows created through jQuery. Despite my efforts to troubleshoot the problem in my code, I remain perplexed. Below is a snippet of ...

"Create a Vue element containing a trio of buttons each displaying a distinct numeral

I am currently dealing with a component that generates three items (boxes) each containing three buttons (created using v-for). The issue I am facing is that when I click on a button, all the numbers inside the buttons change simultaneously. I want to be a ...

Creating dynamic components with constructor parameters in Angular 9

Having trouble passing a value to the constructor in the component generation code. Check out the original code here: https://stackblitz.com/edit/angular-ivy-tcejuo private addComponent(template: string) { class TemplateComponent { @ViewChild( ...