Having difficulty with checkboxes in Vue.js: selecting one checkbox selects all, and struggling to pass dynamic data as the value

Currently, I am facing a complex issue related to dynamic checkboxes in Vue. This is the current state of my code:

     <table class="table table-striped">
      <thead>
       <tr>
        <th>Student</th>
        <th>Status</th>
        <th>Remarks</th>
       </tr>
      </thead>
      <tbody>
       <tr v-for="(s,index) in c.data['Students']" :key='index'>
        <td> {{s['First Name']}} {{s['Last Name']}} </td>
        <td>                              
         <input type="checkbox" 
           :id="{{s['First Name'] s['Last Name']}}" 
           value="{{student:s['First Name'], status: absent}}" // need to pass object here
           v-model="attendance">
         <label for="absentCheckbox">A</label> 
        </td>
       </tr>
      </tbody>
     </table>

The challenge I'm encountering has two aspects. Firstly, selecting one checkbox results in all others getting selected as well. Secondly, I am struggling to dynamically pass an object in the value attribute for each checkbox. I understand that the line

value="{ student:s['First Name'], status: absent}"
is incorrect, but I'm uncertain about the correct approach or its feasibility. My 'attendance' array must hold objects with both the student name and status values.

The 'attendance' array is present within the data function as required, structured like this:

 data() {
    return {
      attendance: [],
}....

If what I'm attempting isn't achievable, I would appreciate any guidance or suggestions on how to accomplish it. Thank you in advance for your assistance!

Answer №1

If

value="{{student:s['First Name'], status: absent}}" 

If you have hard coded this value in your iteration, it may be the reason why all your checkboxes are checked when clicked.

Ensure that the values of your checkboxes are unique.

To dynamically pass values to your input, use binding. For example:

:value="object"
// Where object is a valid JavaScript object

Binding allows you to pass dynamic values to your template.

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

What is the best way to trigger a modal on Bootstrap using a JavaScript/jQuery function?

I encountered an issue while attempting to call a bootstrap modal using a simple button or link, which may be due to a conflict with my select2 plugin (although I am uncertain). I tried appending the button to the select2 dropdown but it doesn't seem ...

I noticed that my API call is being executed twice within the router function

In my NextJs project, I am utilizing Express for routing. I have implemented a router with a dynamic :id parameter which triggers an axios call to check the ID in the database. However, I am facing an issue where the API is being called twice when the :id ...

Managing browser cache while developing locally

During development testing, how can you selectively disable caching for local scripts and styles while keeping cache enabled for external ones? Ideally in Firefox. When editing css, js, or sprite files on my developmental site, I find myself needing to fr ...

Traversing a two-dimensional array backwards in JavaScript

I am working with an array that contains different teams: The structure looks like this: leagues = new Array( Array('Juventus'), Array('Milan'), Array('Inter')); My goal is to iterate through the array and generat ...

What is preventing me from setting the maxwidth in Android WebView during onLayout?

I am attempting to customize the onLayout function of a WebView in order to limit the size of large images to fit within the screen size. Within my extended WebView, I have tried the following code: @Override protected void onLayout(boolean changed, i ...

jQuery is implemented prior to the completion of HTML loading

Is there a way to ensure that HTML content loads before executing a JavaScript function? $(document).ready(function() { var x = 10; if(x == 10) { $('h1').text("Its changed !"); alert("Test"); } }) <h1>Hello< ...

Using Laravel: Validate username existence with jQuery AJAX before form submission

After creating a registration form with numerous fields, I encountered an issue when submitting data and receiving validation errors. The user would have to refill empty inputs, causing unnecessary delays. To streamline the process, I am looking to impleme ...

Unable to locate the AngularJS controller after attempting to paste the code

Currently enrolled in the AngularJS Mastery Course on Udemy, I encountered an odd issue that has left me scratching my head. The code provided seems to function flawlessly for most users, except for a select few. index.html <html lang="en" ng-app=&apo ...

Is there a way to retrieve the information from the v-text-field without using the v-model directive?

<div v-for="i in parseInt(questionCount)" :key="i"> <v-layout> <v-flex xs6 offset-3 mt-15" > <label for=""> Enter question number {{index}}:</label> <v-text-fi ...

"MongoDB Aggregating Data with Nested Lookup and Grouping

I have 3 collections named User, Dispensary, and City. My desired result structure is as follows: { _id: , email: , birthdate: , type: , dispensary: { _id: , schedule: , name: , address: , phone: , u ...

Retrieve information from an XML document

I have some XML content that looks like this: <Artificial name="Artifical name"> <Machine> <MachineEnvironment uri="environment" /> </Machine> <Mobile>taken phone, test when r1 100m ...

Implementing a CSS stylesheet that is triggered when the user reaches the top of the webpage, and incorporating an

Currently, I have code that controls the hiding and showing of my navigation menu when a user scrolls up on the page. $.fn.moveIt = function(){ var $window = $(window); var instances = []; $(this).each(function(){ instances.push(new moveItItem($( ...

What is the best way to implement a clickable icon that triggers a datepicker using md bootstrap?

I am currently working on a Vue.js project that utilizes MdBootstrap. I would like to add an icon with a calendar which, when clicked, opens up a datepicker for selecting a date. Is there a way to achieve this functionality? I have reviewed the documenta ...

Concealing a button once the collapse feature is toggled in Bootstrap

The following code snippet from the bootstrap website demonstrates how to use collapse functionality: <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Link with href & ...

In Laravel Blade, I am looking to display a Modal popup and dynamically pass data based on the user's ID

When a user clicks on the "View Details" Button, I need to display a popup modal with information specific to that user. The data for each user is stored in the $user variable. I would like to achieve the same functionality as demonstrated on this website ...

The return value from vue-query is ObjectRefImpl, not the actual data

Greetings to the Vue.js community! As a newcomer to Vue.js, I am seeking guidance on fetching data using vue-query, Vue.js 3, and the composition API. The data returned to me is ObjectRefImpl, but when I try to print the values, I encounter the error: "Pro ...

Tips for accessing touch events within the parent component's area in React Native

I implemented the code below in my React Native app to disable touch functionality on a specific child component. However, I encountered an issue where the touch event was not being detected within the area of the child component. How can I fix this prob ...

A guide to update values in mongodb using node.js

I'm working on tracking the number of visitors to a website. To do this, I've set up a collection in my database using Mongoose with a default count value of 0. const mongoose = require('mongoose'); const Schema = mongoose. ...

What is the best way to modify a variable in a nested element using ng-click in the parent element?

Review this code snippet: <section class="page-section about-us" scroll-bookmark="about-us" ng-click="activeSection=true" ng-init="activeSection=false"> <div class="page-content sub-content active-section">{{activeSection}} < ...

Steps for transforming a numerical value into an array with individual elements, such that the maximum value in the array will be 1

Can someone assist me? I have a value of 4.8 (it represents a rating of 4.8/5). Now I want to convert it into an array with the following structure: [1, 1, 1, 1, 0.8] What I mean is that the value should be split into 5 elements, with each element not ...