What is the solution to deselecting all other options when selecting one in an <input type='radio'>?

As a newcomer to Vue/Nuxt, I'm currently facing an issue with a group of radio inputs that do not unselect when another option is chosen. After some investigation, it seems like the problem may lie within this specific code snippet below. My focus is on understanding and fixing the v-model=$store.state.currentModifiers set by the previous developer. How can I resolve this bug where selecting one option does not unselect the others?

https://i.sstatic.net/i08if.png

<div
                  v-for="(modifier, index) in getMenuModifiers(
                    groupModifiers._id
                  )"
                  :key="'MMi' + index"
                >
                  <input
                    type="radio"
                    :id="index"
                    :ref="modifier._id"
                    :value="modifier"
                    @change="check($event)"
                    v-model="$store.state.currentModifiers"
                  />
                  <label :for="modifier._id">{{ modifier.title }}</label>
                </div>

Answer №1

From what I gather, the v-model acts as the model and connects the different radio buttons that have the same value for this attribute.

It is important to ensure that the value you assign is consistent among the radio buttons you want to group together.

new Vue({
  el: '#sauceChoice', data: {sauce: ''}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>

<div id="sauceChoice" class="demo">
  <h3>Salad Sauce</h3>
  <input type="radio" v-model="sauce" value="Blue Cheese">Blue Cheese<br>
  <input type="radio" v-model="sauce" value="Sweet Curry Mustard">Sweet Curry Mustard<br>
  <input type="radio" v-model="sauce" value="Ranch">Ranch<br>
  <br>
  <p>value: {{sauce}}</p>
</div>

Source: Vue.js > Form input Bindings > Basic Usage > Radio

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

Arranging website elements to conform to a compact grid system

Recently, I've been brainstorming a unique concept for a website layout that involves a background composed of tiny color-shifting squares, each measuring about 10px. The challenge I'm facing is aligning the elements on the page with this grid, a ...

Consistent manipulation of the DOM through the Drag/Touchmove event

Seeking to incorporate Mobile Components through native Javascript and AngularJS. During my work on developing a Pull To Refresh directive for AngularJS, I utilized the touchmove event on a UL list. The goal was to pull a concealed div over a list with cu ...

Looking for tips on programmatically adjusting the row count in a react table? Calling all React developers!

Currently, I have a table that is displaying data from an APP_DATA object. However, I am looking to add a column showing the number of rows dynamically next to each row. How can I achieve this? Keep in mind, only "prt" and "cat" are arrays, so you can onl ...

Failure to trigger bind action in connector.php for elfinder, a Javascript file manager plugin

function log() { $data = array( 'folder_id' => 1, 'user_id' => 1 ); $this->Folder_model->share($data); } function access($attr, $path, $data, $volume) { return strpos(basename($path), '. ...

Creating a seamless integration between a multi-step form in React and React Router

I've been learning how to use React + ReactRouter in order to create a multi-step form. After getting the example working from this link: , I encountered an issue. The problem with the example is that it doesn't utilize ReactRouter, causing the ...

What is the correct way to handle fetch timeouts in a React component?

Utilizing a JavaScript timeout, I am able to fetch Dogs from my API successfully. However, there are instances where the timeout fails to clear properly: import { useState, useEffect, useCallback } from 'react'; const DogsPage = () => { c ...

Efficiently sorting items by category name in PHP with Ajax

Currently, I am working on a functionality that involves two dropdown lists. The first one, located at the top, is for selecting a category of meals. Each option in this dropdown has an associated id_cat value. <option value="1">Pâtis ...

The JSON data script is not functioning properly

Is this JSON formatted correctly? Why is it not displaying in the element with #id? I found a similar code snippet on https://www.sitepoint.com/colors-json-example/, copied and replaced the values but it's not functioning. Can anyone shed some light o ...

How to sync two carousels in Bootstrap 5 to slide simultaneously with just one click on the next and previous buttons

I am trying to implement dual sliding carousels using Bootstrap 5, but I am encountering issues with getting them to slide simultaneously. Despite incorporating data-bs-target=".carousel", the synchronization isn't working as intended in my ...

Retrieve JSON information via AJAX

Consider the following JavaScript AJAX request: $.ajax({ type: "POST", url: "/myurl", async: false, data: JSON.stringify({}), contentType: "application/json", complete: function (data) { var ...

What is the method for creating a JavaScript array that closely resembles the provided example?

My task is to create an addRows method using specific data structure as shown below. data.addRows([ ['UK', 10700,100], ['USA', -15400,1] ]); However, the data I have available is in a different format. How can I transform ...

BufferGeometry's Vertices

Since version 125, the use of THREE.Geometry has been deprecated. As we update our code base, we are encountering errors that are proving difficult to resolve. Our current task involves creating a sphere and applying a raycaster on it to determine the int ...

The Express Electron framework does not support importing local JavaScript files

Despite my extensive search before flagging this as a duplicate, I have not been able to find the solution I need. I am encountering issues with using express and electron. Everything runs smoothly when I execute npm start (the start script in package.jso ...

The error message "TypeError: render is not a function" is encountered when attempting to call and display information

I am currently working on a movie app using React JS and I encountered an error while trying to render a component based on API data. TypeError: Render is not a function The code works perfectly fine for TvListProvider, but I'm facing this error wi ...

The single-page anchor link is positioned just below a few pixels, connecting with the #link

Hey there! I'm currently working on a single-page website and running into an issue. When I click on the anchor link in the menu, it seems to go slightly below the intended area, just like in this image https://i.sstatic.net/3hAvO.jpg I want the beha ...

insert a gap between two elements in the identical line

Is there a way to create spacing between two text fields in the same row? I have tried using margins, paddings, and display flex in the css file but haven't been successful. import "./styles.css"; import TextField from "@material-ui/cor ...

Unveiling the Power of Ionic and React for Component Repetition

I'm having trouble figuring out how to repeat my component multiple times using react in Ionic. Can someone assist me with this? Here's an example: In my Component.tsx file, I have the following code: import React from 'react'; import ...

Changing the color of a selected variant in a BootstrapVue table using Vue.js

I am making use of the bootstrap-vue table row select support feature and I would like to change the color of the selected-variant prop of the b-table. Currently, the color is set to info for the selected row in the table. I wish to customize it and set th ...

What steps should I take to resolve the error message "Error: srcmain.ts is not found in the TypeScript compilation?"

I've exhausted all possible solutions on StackOverflow and have even gone as far as uninstalling both Node and Angular three times in the span of three days. I'm completely stumped as to why this issue keeps occurring specifically when using "ng ...

The Vuetify tooltip has been updated to display within a button located inside a card element

Here is a template I have: <template> <div> <v-card :color="variant"> <v-card-actions> <v-tooltip top> <v-btn icon slot="activator" @click="openConsole"> ...