What causes the checkbox to automatically check the following checkbox after being checked?

I'm working on a small todo list application using Vue. The issue I'm facing is that when I check the first checkbox to mark a task as complete, the next task's checkbox gets automatically checked as well, but this does not happen with the last checkbox.

I have tested this on my local machine but unfortunately it did not work as expected. Here is the link to the code snippet

<div id="app">
  <h1>Incomplete Tasks</h1>
    <ul>
         <li v-for="task in incompleteTasks">
            <label> 
               <input type="checkbox" v-model="task.completed">
               {{ task.description }}
            </label> 
         </li>
    </ul>
   <h1>Complete Tasks</h1>
    <ul>
         <li v-for="task in completeTasks">
            <label> 
               <input type="checkbox" v-model="task.completed">
               {{ task.description }}
            </label> 
         </li>
    </ul>
new Vue({
    el: '#app',

    data: {
        tasks: [
            { description: 'First Task', completed: false },
            { description: 'Second Task', completed: false },
            { description: 'Third Task', completed: false },
            { description: 'Fourth Task', completed: false }
        ]
    },

    computed: {
        incompleteTasks() {
            return this.tasks.filter(task => !task.completed);
        },

        completeTasks() {
            return this.tasks.filter(task => task.completed);
        }
    }
})

Answer №1

When using v-for to loop through elements, it's important to add a unique key for each item. In this case, since there is no unique id present in the current data, I have used the description field as an example.

<li v-for="item in unfinishedItems" :key="item.description">
<li v-for="item in completeItems" :key="item.description">

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

Creating custom ExpectedConditions with Protractor for detecting attribute changes

I've been working on creating a custom ExpectedConditions method that can wait for an element attribute to change. Here is the approach I came up with: const CustomExpectedCondition = function() { /** * Check if element's attribute matches ...

Modifying the page's left attribute dynamically with jQuery based on window resize

I am currently facing a small issue with my code. My goal is to update the 'left' CSS property of certain elements based on the difference between their current left value and the page resize amount. This way, when the background moves with a pag ...

The utilization of the 'this' keyword within an object is not feasible due to its placement within a separate function

The issue I am facing is while using vue.js, but I believe it might also be applicable in plain JS. The problem arises when I am inside a function that is within another function; I have to reference variables by their full path such as Object.variable i ...

Looping through items with ng-repeat and creating a submenu with M

When constructing a menu from a JSON file with submenus using the JQuery.mmenu plugin, I encountered an issue when trying to implement the submenu structure with ng-repeat. The raw HTML approach worked perfectly, but as soon as I introduced ng-repeat to dy ...

Step-by-step guide on incorporating play/pause buttons for two distinct Bootstrap 5 carousels

I have been struggling to incorporate carousel controls on my website. I have tried looking at various examples on different platforms, like Stack Overflow, but I am only able to get one set of controls to work at a time. Here is my current setup: ...

What could be the reason my div is not being hidden in jQuery?

Creating a quiz layout for school is my current project, and I'm just getting started. My goal is to have the questions disappear once the 'next question' button is clicked. The issue arises after the second question because instead of the ...

The Art of Using Ajax and jQuery in Joomla

Hello! I am currently facing an issue with the custom pagination for a Joomla component. I am attempting to create a list of user articles, displaying 3 posts per page without refreshing the webpage. After hours of searching for a solution, I decided to i ...

What is the best way to align two bootstrap buttons next to each other?

Is there a way to align buttons on a modal side by side? One button is a download link and the other a mirror link. I attempted to use a custom class with CSS property "display: inline-block;" but it did not work as expected. Any suggestions on how to achi ...

Why is the promise triggered within the .then() function even with an error response in Laravel?

Currently, I am developing a Single Page Application using Laravel, vue.js, vuex, and vue router. I have created an action in my store for logging in, but I noticed something unusual when attempting to log in with invalid credentials. Strangely enough, eve ...

Javascript recursive method for fetching data entries

Seeking a solution to retrieve interconnected records based on a parent column, where the relation can be one or many on both ends. After attempting a recursive function without success, I found my code became overly complex and ineffective. Is there a st ...

Is there a way to display just one element without affecting the other elements within the same class?

I need to create a series of buttons that can appear and disappear when clicked. Here's how it should function: When I click on link 1 (link 2 is currently hidden). Link 2 should then become visible. The challenge lies in distinguishing between mu ...

Creating a Dynamic Navigation Bar with CSS and JavaScript

I have encountered an issue with my responsive menubar where the dropdown button does not have any style when clicked. function myFunction(){ var x = document.getElementById("myMenubar"); if (x.className === "menubar"){ x.className += "responsiv ...

What other methods can be used to initiate an Ajax request?

I'm curious about the most efficient approach to making an AJAX call. My current code works perfectly fine: $.ajax({ url: "/rest/computer", type: "GET", dataType: "json", data: { assessmentId: "123", classroomId: " ...

Php file not receiving data from ajax post method

forget.php PHP: if (! (empty($_POST['emailforget'])) ) { echo "here in the function"; } else { echo "here"; } AJAX: $("#passreset").on('click', function(e) { var emailforget = $("#tempemail").val(); alert(emailforget); ...

VueJS and express implement CSRF token handling for secure POST requests

For my web application, I am using VueJS (cli 3) with axios for the front-end and NodeJS with ExpressJS for the back-end. Currently, I am working on securing the post user edit functionality by implementing CSRF tokens. In my Vue component (edit user), th ...

Ways to showcase information from an angular service

I'm struggling with displaying data from a service in my HTML view using AngularJS. My goal is to show a list of submitted forms called Occurrences in the view. When clicking on a list item, I want to be able to view all the data fields submitted thro ...

Troubleshooting CSS override issues when swapping components in ReactJS

Access.js import React from 'react' export default class Access extends React.Component { componentWillMount(){ import ('./styles/access_page.css'); } .... <Link to="/new-account">Sign Up</Link> } Cr ...

Debugging JavaScript in ASP .NET (solving quick breakpoint problems)

There seems to be a mystery about setting breakpoints in my JavaScript code - sometimes it works, other times it doesn't. Despite all efforts, I can't seem to figure out what factors contribute to this inconsistency. While debugging the dynamic p ...

Leverage external libraries in Angular

I discovered a library that I want to incorporate into my app: https://www.npmjs.com/package/jquery-animated-headlines However, I am struggling with the process of importing it. Firstly, I have added these lines in my angular-cli.json: "styles": [ . ...

Click Action on CanJS Table

I am currently developing a canJS application and have been able to successfully handle the click event for an HTML table using the code below. 'table td click':function(el,event){ console.log('clicked ',el.text()); } ...