What steps can be taken to receive an alternative result when selecting a checkbox?

Currently, I am tackling the issue with checkboxes in Vuetify. The challenge lies in achieving a different output for the second {{ selected.join() }}. For example, when I select the checkbox labeled "Social Media," I receive the text "On our social media" at the first {{ selected.join() }}, but I desire a distinct string (such as "on our social media page") for the second occurrence.

<v-checkbox
      v-model="selected"
      label="Social Media"
      value="On our social media"
    ></v-checkbox>
    <v-checkbox
      v-model="selected"
      label="Website"
      value="on our website"
    ></v-checkbox> 
Output: {{ selected.join() }} ...... {{ selected.join() }}

Answer №1

the v-model for both checkboxes is connected to the same attribute selected. This means that if you click on one checkbox, both will be updated.

Instead of binding a checkbox to an array, it would make more sense to bind them to two different boolean values. Then, you can create a computed property that returns your desired result based on the values of these booleans:

<template>
  <div>
    <v-checkbox v-model="checkbox1" label="Social Media"></v-checkbox>
    <v-checkbox v-model="checkbox2" label="Website"></v-checkbox>
  </div>
</template>

<script>
export default {
  data() {
    return {
      checkbox1: false,
      checkbox2: false,
    };
  },
  computed: {
    myWantedResult() {
      const tempArray = [];
      this.checkbox1 && tempArray.push('On our social media');
      this.checkbox2 && tempArray.push('On our website');
      return tempArray.join();
    },
  },
};
</script>

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

Retrieve the object from the PHP array of objects by searching for the one with the ID equal to 2

Within the "list_member" class, I have defined various attributes such as $id, $email, $lastchange, $active, $hash, and $list_id. class list_member { public $id; public $email; public $lastchange; public $active; public $hash; public $list_id; ...

Converting Variable Values to Element IDs in JavaScript: A Helpful Guide

Is it possible to declare a value in variable A and then access that value as an id in variable B using the method getElementById()? var A = 10; var B = document.getElementById(A); console.log(B); ...

Understanding information in Backbone.js

I have multiple backbone models with nested sub-models. Here's how I've approached the solution: Models.Base = Backbone.Model.extend ({ relatedModels: {}, /** * Parses data based on the list of related models. * * @since ...

What should be transmitted to the front-end following the successful validation of a token on the server?

My process starts with a login page and then moves to the profile page. When it comes to handling the token on the backend, I use the following code: app.use(verifyToken); function verifyToken(req, res, next) { if (req.path === '/auth/google&ap ...

Exploring the Power of NPM Modules in an Electron Renderer

Having trouble accessing lodash in an electron renderer. I'm a beginner with Electron and know that both the main process and renderer (local html file) have access to node. I can require something from node core like fs and it works fine, but when I ...

Removing multiple items from a list in Vue JS using splice function

I have a problem with my app's delete feature. It successfully deletes items from the database, but there seems to be an issue in the front-end where I can't remove the correct items from the list. Check out this demo: https://i.sstatic.net/eA1h ...

Create dynamic elements in Vue.js components based on an object

I'm currently working on a component that will display elements within VueJs virtual dom using Vuex state. However, I have encountered an error that I am unable to comprehend and resolve: Avoid using observed data object as vnode data: {"class":"b ...

PHP/MySQL clarification regarding time slots

Could someone assist me with this discussion I found? Due to my low reputation, I am unable to comment for further clarification. Although I grasp the solution provided in the mentioned discussion, I am struggling to comprehend how to pass the data to my ...

Troubleshooting Problem with Angular JS Page Loading on Internet Explorer 9

My angularjs single page application is encountering issues specifically in IE9, despite functioning perfectly in Chrome and Firefox. The initial load involves downloading a substantial amount of data and managing numerous dependencies through requireJS. ...

Transmitting information securely and remotely between two online platforms

I own two websites and another at When a user clicks on something on example1.com, I want it to trigger a popup from example2.com. Then, I need to send some data back to example1.com using GET parameters and be able to detect it using jQuery or JavaScrip ...

D3 - Error: Unable to access property 'text' of an undefined method

I want to create a visual representation of significant events that have occurred in the United States over the past 30 years. Below is a snippet of code I am using for this project: var mevent = svg.append("text") .attr("class", "year event") .at ...

Comparing the syntax of JSON to the switch statement in JavaScript

I recently came across a fascinating post on discussing an innovative approach to utilizing switch statements in JavaScript. Below, I've included a code snippet that demonstrates this alternative method. However, I'm puzzled as to why the alter ...

Exploring Angular2's interaction with HTML5 local storage

Currently, I am following a tutorial on authentication in Angular2 which can be found at the following link: https://medium.com/@blacksonic86/authentication-in-angular-2-958052c64492 I have encountered an issue with the code snippet below: import localSt ...

I am looking for a way to hide email addresses using Regex in JavaScript

I'm looking for a way to hide an email address [email protected]=> [email protected] using JavaScript I attempted to use the /(?<=.{2}).(?=[^@]*?@)/ regex, but it is not functioning properly in Internet Explorer and Mozilla. I need a ...

What is the best way to dynamically add and index dimensions of arrays in PHP?

In my PHP class, I have a complex array and two member functions The first one takes in two integers: one representing the dimension and the other the value: private $complexArray; function setValueToGivenDimension($dimension, $value) My goal is to set ...

Exporting all components using require: A complete guide

Currently, I am working on a Vue js application where I am tasked with exporting all the files and components from a specific directory. These files/components need to be imported into a separate file named paths.js. If I use the require function to impor ...

Is converting the inputs into a list not effectively capturing the checkbox values?

On my website, I have a div that contains multiple questions, each with two input fields. When a button is clicked, it triggers a JavaScript function to add the input values to a list. This list is then intended to be passed to a Django view for further pr ...

JavaScript: abbreviated way to selectively append an element to an array

Currently, I am in the process of creating a Mocha test for a server at my workplace. When dealing with customer information, I receive two potential phone numbers, with at least one being defined. var homePhone = result.homePhone; var altPhone = ...

Activate the textbox without utilizing `.focus()` method

I am encountering an issue with a small iframe on my page. The content within the iframe is larger than the window itself, requiring users to scroll around to view it in its entirety. Within this iframe, there is a button that, when clicked, triggers an an ...

Incorporating Blank Class into HTML Tag with Modernizr

Currently, I am experimenting with Modernizr for the first time and facing some challenges in adding a class to the HTML tag as per the documentation. To check compatibility for the CSS Object Fit property, I used Modernizr's build feature to create ...