Activate Vue JS if the input is checked

My goal is to make the next button clickable only when a checkbox is selected. I am attempting to validate whether the checkbox is checked or not, enabling the button for the next step only when it meets this condition. Once the user moves on to the next step, the button should be disabled again.

In my setup, I'm importing the Detailsform0.vue into ProductPage.vue using an array called items[]. Each form is contained in a separate file. Can anyone assist me with implementing the functionality to enable the button upon checkbox selection and disable it again after moving to the next step? Thank you in advance. https://i.sstatic.net/D2Sob.png

DetailsForm0.vue This is a test. I have filled out all the fields on this page.

\\\\\ ProductPage.vue 
<template>
    <component v-bind:is="currentStep.details"></component>
    <button class="btn" v-on:click="backStep" id="back">Back</button>
    <button class="btn" v-on:click="nextStep" v-bind:disabled="checked === false" id="next">Next</button>
</template> /// DetailsForm0 <template>
    <component v-bind:is="currentStep.details"></component>
    <button class="btn" v-on:click="backStep" id="back">Back</button>
    <button class="btn" v-on:click="nextStep" v-bind:disabled="checked === false" id="next">Next</button></template>

  data: function () {
    return {
      items: [
        { stepTitle: 'Step 1', details: DetailsForm0 },
        { stepTitle: 'Step 2', details: DetailsForm1 },
        { stepTitle: 'Step 3', details: DetailsForm2 },
        { stepTitle: 'Step 4', details: DetailsForm3 }
      ],
      activeNumber: 0,
      checked:false
    }
  },

Answer №1

     [[[ DetailsForm0.vue]]] *** The checkbox comes from the DetailsForm0.Vue file which contains the following code***
<template>
    <input type="checkbox" v-model="checked">I have filled out this page<br>
</template>
<script>
export default {
  name: 'DetailsForm',
  data: function () {
    return {
      checked: false
    }
  }
}
</script>
     [[[ ProductPage.vue]]] *** The DetailsForm0.Vue is imported into the ProductPage.vue file ***
    <template>
        <component v-bind:is="currentStep.details"></component>
        <button class="btn" v-on:click="backStep" id="back">Back</button>
        <button class="btn" v-on:click="nextStep" v-bind:disabled="checked === false" id="next">Next</button></template>

      data: function () {
        return {
          items: [
            { stepTitle: 'Step 1', details: DetailsForm0 },
            { stepTitle: 'Step 2', details: DetailsForm1 },
            { stepTitle: 'Step 3', details: DetailsForm2 },
            { stepTitle: 'Step 4', details: DetailsForm3 }
          ],
          activeNumber: 0,
          checked:false
        }
      },

    <script>
    methods: {
        toggleActive: function (index) {
          this.activeNumber = index
        },
        nextStep: function () {
          this.toggleActive(this.activeNumber + 1)
          this.checked = 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

Automating the compression of JavaScript with YUI Compressor, excluding specific files

I came across a helpful solution on this Stack Overflow thread: How can I automate the compression of JavaScript files using YUI Compressor? But here's my dilemma: I have a bunch of jQuery files in my ~/Scripts directory that are already compressed ...

Toggle the visibility of a component in React by managing its state

Currently, I am faced with the challenge of toggling the visibility of a component based on a state value: import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; import Button from ' ...

Click to open the file browser by using the onclick event in Material-table actions

Currently, I am working with a Material table component from "@material-table/core" My goal is to implement an action that enables users to upload a file within this table. I am facing some challenges on how to trigger the file browser when the ...

Webpack: Moving JSON files with the file-loader

Currently utilizing Webpack's module.loaders and file-loader to duplicate multiple js-files during compilation: module.loaders = [ { test: /app\/locale\/moment\/.*\.js$/, loader: "file-loader?name=locale/moment/[name].[ext]" } ...

A Comprehensive Guide to Handling Errors in Angular 4: Passing the err Object from Service to Component

Currently, I am in the process of developing a login page using Angular for the front-end and Spring Security for the back-end. Everything appears to be functioning correctly, except for handling exceptions when attempting to catch errors from the service ...

Struggling with incorporating elements into a dynamic CSS3 banner design?

Struggling to add up to 10 text items to the CSS3 animated banner. Having difficulty getting the items to display properly. I'm curious if there is a simpler way to achieve this with animations as shown in this example: http://jsfiddle.net/zp6B8/1/ & ...

Execute an asynchronous function in Javascript, then output the returned data to the console

Is there a way to effectively handle the data returned from an async function? example: JS FILE: async function getData(){ try { $.getJSON('./data.json', (data) => { return data; }); } catch(error ...

Tips on customizing the appearance of mat-card-title within a mat-card

Is there a way to truncate the title of a mat card when it overflows? I tried using the following CSS: overflow:hidden text-overflow:ellipsis white-space: nowrap However, the style is being overridden by the default mat-card style. I attempted to use mat ...

What is the purpose of the <React.StrictMode></React.StrictMode> component in React?

I stumbled upon this code snippet while practicing React, and I'm curious about its functionality. For example: const App = () => { return ( <React.StrictMode> <div id="cool-attribute"> <h1>Welcome to the Jun ...

Is there a way to set up a loop for managing four separate drop-down lists?

While the code is functioning properly, I am determined to streamline it into a loop. Unfortunately, all my attempts thus far have been unsuccessful. The code displays four drop-down lists with different Id's, but they share the same class name (optio ...

Sending multiple arguments to a Vuex action

In the Vue Component code snippet below, I have a method: loadMaintenances (query = {}) { this.getContractorMaintenances(this.urlWithPage, query).then((response) => { this.lastPage = response.data.meta.last_page }) } I am trying to pass the par ...

Testing a Component Function in ReactJS: A Step-by-Step Guide

Testing methods in a Meteor application using mocha/chai can be done like this: describe('postMessage', () => { it('should add message', (done) => { // EXECUTE const messageId = postMessage.call({ articleId: 123, conten ...

What could be the reason for PhantomJS getting stuck when jQuery is invoked?

Currently, I am using PhantomJS 2.0.0 on a Mac OS X Yosemite: $ phantomjs --version 2.0.0 The script I have attached below seems to get stuck at the line where it calls $('h1').size(): system = require('system'); function usage() { ...

Ways to maintain an array in Vuex even after mutations take place? (Specifically focusing on persisting data through browser refresh)

I am in the process of developing a basic shopping cart and I need guidance on how to persist an array containing cart data when executing the addProduct mutation below. Is there a way to save this data temporarily to prevent it from being lost due to br ...

Bringing in CSS variables to a Typescript document

In order to streamline the styling process for our app, we have established a theme.css :root file containing a set of commonly used variables that can be accessed across all other .css files. However, some of our older code follows a similar structure bu ...

How can PHP validate a URL when the ID parameter is missing?

On my website, I am able to display a single post using view_post.php?id=1. However, when attempting to display a post with an invalid ID such as view_post.php?id= or view_post.php?id, nothing is shown. To troubleshoot, I attempted to log the database quer ...

Develop a distinctive JavaScript solution that enables an image to appear in fullscreen upon loading the page, and then smoothly fade away after precisely

I have been trying to incorporate a feature on my Shopify frontage website where our logo appears fullscreen and then fades away or disappears after a few seconds, allowing people to access the rest of the website. However, I am facing difficulty in making ...

Tackling the challenge of merging PDF files and designing a Table of Contents feature reminiscent of Acrobat in Node.js and JavaScript

I am currently implementing the following code snippet: const pdfmerger = require('pdfmerger') var pdfStream = pdfmerger(array_of_pdf_paths) var writeStream = fs.createWriteStream(final_pdf_path) pdfStream.pipe(writeStream) pdfmerger(array_of_pd ...

Exploring ways to retrieve nested values from JSON data using the Instagram API and Javascript

Trying to modify the script found at https://github.com/bigflannel/bigflannel-Instafeed in order to access Instagram photos on a website. Unfortunately, the script does not currently support displaying photo comments. I attempted to make modifications that ...

The most effective method for incorporating a header and footer into an HTML page utilizing a variety of client-side frameworks

Looking for a solution for my HTML project where I want to incorporate a header and footer to minimize rework. Any suggestions on a good approach? I have experimented with AngularJS using ng-include, and here is the code snippet: var app = angular.module ...