storing label text from checkboxes as an array in a Vue.js component

I need to save the selected checkbox label names in an array.

<template>
<div class="q-gutter-sm">
              <q-checkbox dense v-model="add_info" label="Data Structures and Algorithms" color="teal" /><br />
              <q-checkbox dense v-model="add_info" label="High Level Design" color="teal" /><br />
              <q-checkbox dense v-model="add_info" label="Low Level Design" color="teal" /><br />
              <q-checkbox dense v-model="add_info" label="Development (Backend, Frontend, Fullstack)" color="teal" />
            </div>
</template>
<script setup>
import { ref } from 'vue'


const add_info = ref([])

</srcipt>

Answer №1

This particular solution is working really well

<script setup>
import { ref } from 'vue'

const selectedLabels = ref([])
</script>

<template>
  <div>
    <p>array of selected labels {{ selectedLabels }}</p>
    <input type="checkbox" id="checkbox" v-model="selectedLabels" value="awesomeLabel" />
    <label for="awesomeLabel">This label is simply awesome!</label>
  </div>
</template>

View the implemented code here

PS: if desired, you can treat awesomeLabel as another ref for reusability purposes.

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 create a non-reactive value in Vue.js?

In my Vue.js app, I am facing an issue where an array value is becoming reactive even though I want it to remain un-reactive. The array should only be updated when a specific "refresh" action is completed. However, every time a new value is assigned to the ...

How to efficiently use .filter() in a React useState setter while looping through .forEach() - A step-by-step guide

I am looking to delete items from an array that is stored in the state of cart. This needs to be achieved by going through the strings that are saved in the array of selectedCart. If a string in selectedCart matches a string in cart's object/key, the ...

Adjusting the viewpoint scale while zooming in and out

$(window).height() retrieves the window's height when the page is initially loaded. However, my concern lies in obtaining the updated viewpoint height when zooming in or out. Is there a feasible solution for this issue? The resizing functionality on ...

Unable to utilize the resolved value received from a promise and returned from it

Within the code snippet below, I am retrieving a Table object from mysql/xdevapi. The getSchema() and getTable() methods return objects instead of promises. The purpose of this function is to return a fulfilled Table object that can be used synchronously i ...

Incorporating a PHP file containing both PHP and JavaScript variables into an AJAX document

I'm facing an issue with my application that involves a language file called "lang.php", along with "index.php" and "ajax.php" files. The "lang.php" file contains both PHP and JavaScript variables which I include in both "index.php" and "ajax.php" to ...

Iterating through every variable on the webpage using JavaScript

After successfully retrieving all JavaScript variables using the instructions provided in this topic, I decided to take it a step further. However, I encountered a challenge when trying to extract strings that were not declared as variables. For instance, ...

Customizing the Steps Component in Ant Design

Currently, I am utilizing the Steps component from Ant Design. My goal is to enhance its functionality by adding additional components, like a button placed next to each step's description to make it more interactive. Furthermore, I am looking to inc ...

Which child node of the html tag represents the "text"?

In my quest for answers, I have searched extensively but to no avail: As we all know, when a web page is loaded in a browser, it generates a tree-like structure called the Document Object Model (DOM). This allows Javascript to manipulate the elements of t ...

The hidden textbox loses its value when submitting

I have a form with fields and a RequiredFieldValidator. Additionally, I have another textbox that is hidden which gets populated by a JavaScript function: <script type="text/javascript"> $(document).ready(function (sender, args) { $("#myTextFiel ...

Unable to execute controller due to service call testing failure

I'm currently working on writing a code to test the service call in my controller. The goal is to unit test a specific function within the controller that makes the service call and retrieves data. While I am using local JSON for testing purposes, the ...

Set the value of a variable to the result of a JavaScript function

I recently wrote a function that retrieves JSON data from a specified URL. Here's what the function looks like: function getJSON(url) { request.get({ url: url, json: true, headers: { 'User-Agent': 'request&a ...

Verify and include phone number entry using Jquery

My input field always requires a + sign to be the first character. HTML <input id="phone"> JS $("#phone").keydown(function (e) { $(this).get(0).value+="+"; // Allow: backspace, delete, tab, escape, enter and . if ($.inArray(e.keyCode, [ ...

Refreshing ng-repeat when there are modifications to scope variables that are unrelated to the data being displayed

In the process of developing an Angular (1.2.1) application, I encountered a situation where I have a directive that includes an ng-repeat in its template. The code snippet looks something like this: <div ng-repeat="item in list | filter: filterList"&g ...

Understanding the distinctions among variables in typescript

Can someone explain the difference in Typescript between "!option" and "option"? It seems like they are not equivalent. const limit = !options.limit || options.limit === NaN ? 0 : options.limit ...

Guide on leveraging a private GitHub repository as a yarn dependency without installing internal dependencies

Recently, I have been attempting to incorporate a private GitHub repository as a dependency within multiple repositories at my workplace. Within the primary package.json file, our dependency is outlined as follows: "mycompany-models": "https://github.com ...

Encountering a Nuxt App Output Error while Attempting to Create

Trying to start a new Nuxt Project with the command: yarn create nuxt-app <project-name> An error is encountered: C:\Users\AbdulAzeez\AppData\Local\Yarn\Data\global\node_modules\sao\lib\instal ...

Alter Elements in AngularJS Based on Their Relationship to Other Elements

Creating diagonal lines that connect squares in the corner using HTML/CSS is my current project. I am currently accomplishing this by transforming divs with a custom Angular directive, but I'm wondering if there's a simpler way to achieve this wi ...

Troubleshooting: Inability to use the v-html attribute in VueJS

Currently, I am facing a situation where I need to replace a link within a paragraph element using v-html. Here is the code snippet for reference: <p v-html="websiteHTML"></p> The variable websiteHTML contains the following HTML code: <a ...

Error occurred while importing Three.js library: "ERR_ABORTED 404 (Not Found)"

I have been working on following a tutorial on the three.js fundamentals page, but I keep encountering an error when trying to import the module. The error message simply states that the file cannot be found, but I am unable to determine the cause. < ...

A new WordPress plugin that includes a custom designed stylesheet featuring a hidden display property within a specific

After reloading the page, my plugin displays a constructed stylesheet. However, when I access it for the first time or reload with ctrl + f5, the constructed stylesheet does not appear. I have meticulously searched through all of the plugin code looking f ...