Table in Vue.js not updating correctly when using Bootstrap 4 radio button group

Check out the live code sandbox here: https://codesandbox.io/s/crazy-bardeen-53qxk?file=/src/App.vue

I am currently working on adding radio buttons to a Vue.js el-table. Despite my efforts, I am unable to update the state of a variable called ownedFilterGroups when the radio buttons are clicked. The key actionFg within ownedFilterGroups should be able to take on values of 0, 1, or 2 based on the radio button selected by the user. Could you take a look and let me know what might be wrong with my approach? I have consulted the https://getbootstrap.com/docs/4.0/getting-started/introduction/ documentation for creating the radio button group. P.S. I have tried removing the data-toggle attribute, but it did not resolve the issue.

      <el-table
        :data="ownedFilterGroups"
        :default-sort="{ prop: 'FilterGroupId' }"
        v-loading="loading.filter_groups"
        max-height="400px"
        stripe
      >
        <el-table-column
          label="Filter Group ID"
          :sortable="true"
          width="350px"
        >
          <template slot-scope="scope">
            {{ scope.row.filterGroupId }}
          </template>
        </el-table-column>
        <el-table-column label="Action">
          <template slot-scope="scope">
            <div class="btn-group btn-group-toggle" data-toggle="buttons">
              <label class="btn btn-outline-primary active">
                <input
                  type="radio"
                  :name="scope.row.filterGroupId"
                  :id="1"
                  :value="1"
                  v-model="scope.row.actionFg"
                />
                Replace With New Version
              </label>
              <label class="btn btn-outline-primary">
                <input
                  type="radio"
                  :name="scope.row.filterGroupId"
                  :id="2"
                  :value="2"
                  v-model="scope.row.actionFg"
                />
                Append New Version
              </label>
              <label class="btn btn-outline-secondary">
                <input
                  type="radio"
                  :name="scope.row.filterGroupId"
                  :id="0"
                  :value="0"
                  v-model="scope.row.actionFg"
                />
                Do Nothing
              </label>
            </div>
          </template>
        </el-table-column>
      </el-table>

The data model includes a variable:

ownedFilterGroups: [{
    actionFg: 0,
    filterGroupId: "aaa"
},{
    actionFg: 0,
    filterGroupId: "bbb"
}]

Answer №1

The issue you are facing is that the radio buttons are not being highlighted when checked, even though the data property has been updated.

The fix is to bind the class using

:class="{'active': scope.row.actionFg === 0/1/2}"
.

Another problem is that actionFg should be a Number, so the radio box values should also be Numbers. Instead of using value="1/2/0", you should use :value="0/1/2". This is because the radio box value will be a String if you use value="1/2/0".

Updated CodeSandBox

Revised Template:

<template>
  <div>
    <el-table
      :data="ownedFilterGroups"
      :default-sort="{ prop: 'FilterGroupId' }"
      max-height="400px"
      stripe
    >
      <el-table-column label="Filter Group ID" :sortable="true" width="350px">
        <template slot-scope="scope">{{ scope.row.filterGroupId }}</template>
      </el-table-column>
      <el-table-column label="Action">
        <template slot-scope="scope">
          <div class="btn-group btn-group-toggle">
            <label class="btn btn-outline-primary active" :class="{'active': scope.row.actionFg === 1}">
              <input
                type="radio"
                :id="1"
                :name="scope.row.filterGroupId"
                :value="1"
                v-model="scope.row.actionFg"
              >
              Replace With New Version
            </label>
            <label class="btn btn-outline-primary" :class="{'active': scope.row.actionFg === 2}">
              <input
                type="radio"
                :name="scope.row.filterGroupId"
                :id="2"
                :value="2"
                v-model="scope.row.actionFg"
              >
              Append New Version
            </label>
            <label class="btn btn-outline-secondary" :class="{'active': scope.row.actionFg === 0}">
              <input
                type="radio"
                :name="scope.row.filterGroupId"
                :id="0"
                :value="0"
                v-model="scope.row.actionFg"
              >
              Do Nothing
            </label>
          </div>
        </template>
      </el-table-column>
    </el-table>
    {{ownedFilterGroups}}
  </div>
</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

Transforming a THREE.js shader into a PIXI.js shader

I am currently exploring the world of PIXI.js and custom Shaders, and I must admit, it's a bit overwhelming for me. I came across a GLSL Shader (created by DonKarlssonSan) that I would like to convert to PIXI.js in order to compare performance. Any as ...

Using Rails 5 and Ajax: Comments will only be appended if a comment already exists

I have been working on a new feature that allows users to add comments to articles using Ajax. However, I have encountered an issue where the comment only gets rendered successfully through Ajax if there is already one existing comment. The database commit ...

Guide to showcasing console output on a Web Server

Apologies if this question is not the most suitable for this platform. I recently set up Pure-FTPd service on a CentOS server. To check current connections, I use the command pure-ftpwho, which gives me the following output: +------+---------+-------+---- ...

Perform a series of tasks concurrently within a function using Grunt

I am currently utilizing grunt-shell along with other custom tasks in my project. In one of my tasks, I need to execute these tasks sequentially and verify the output of each task. Here is a simplified representation: grunt.task.registerTask('test&ap ...

Vuejs: Limiting the number of items in an li tag to 5

selectPreviousSearch(index) { this.search = this.searchHistory[index]; this.showSearchHistory = false; }, <input class="form-control bg-light-blue" id="SearchText" type="text" v-model="search" @keydown.enter = 'ent ...

What steps can be taken to solve the JavaScript error provided below?

My objective is to create a new variable called theRightSide that points to the right side div. var theRightSide = document.getElementById("rightSide"); Once all the images are added to the leftSide div, I need to use cloneNode(true) to copy the left ...

Using Ajax with Angular services

Recently, I decided to explore Angular JS and Async calls as an alternative to $JQuery. However, I encountered a peculiar issue while making ajax calls. To adhere to 'best practices', I shifted my ajax requests to a service and then initiated th ...

Decoding various JSON arrays received through AJAX requests

After returning two objects as JSON through AJAX, I am facing an issue with accessing the values in these two lists. Previously, when I had only one list, I could parse it easily. data = serialize("json", vm_obj) data2 = serialize("json", user_networks_li ...

Error functions in Angular HTTP Interceptor are not being triggered

I followed the example code for an interceptor from the Angular HTTP documentation, but I am having trouble getting the "requestError" and "responseError" functions to trigger. The "request" and "response" functions are working as expected. myApp.config([ ...

Animating CSS styles in Vue.js based on JavaScript triggers

Within my Vue.js application, I've implemented a login form that I'd like to shake whenever a login attempt fails. Though I have achieved the desired shaking effect, I'm not completely satisfied with my current solution. Here's a simpl ...

Header Stability TransitionAndView

I'm not very experienced with JavaScript, so please bear with me. I'm attempting to create a fixed header that transitions to 50% opacity when scrolled down and returns to full opacity (opacity: 1.0) when scrolled back to the top. Here is my cur ...

The radio button is unable to be deselected within the radiogroup due to the presence of a

I have developed a customized radio button component and want to group them together. However, when I utilize a v-for loop to display multiple radio buttons, they do not deselect when another option is selected. This is the code template for my radio butt ...

Unable to show date/time using v-for loop

I'm facing an issue where I want to display the datetime in a v-for loop, but it ends up showing the same time repeatedly. Is there a solution to avoid this problem? v-for loop example: <div class="location-box-container"> <ul c ...

IE9 presents a frustrating issue where the jQuery select box value is returning as

I've been battling a bug for over 2 hours now. My javascript code is supposed to generate a two-level select box for tasks and subtasks from JSON data. However, I recently discovered that this code doesn't function properly on IE9, and possibly ...

Is it advisable to solely rely on CDN for incorporating Bootstrap JS components, or are there any potential drawbacks to

I'm in the process of customizing Bootstrap using my own styles, by utilizing a local version of the source SASS files as outlined in the official documentation, and importing them into a custom.scss file. My main focus is on altering the visual aspe ...

The essential guide to creating a top-notch design system with Material UI

Our company is currently focusing on developing our design system as a package that can be easily installed in multiple projects. While the process of building the package is successful, we are facing an issue once it is installed and something is imported ...

What could be the reason why my JavaScript code for adding a class to hide an image is not functioning properly?

My HTML code looks like this: <div class="container-fluid instructions"> <img src="chick2.png"> <img class="img1" src="dice6.png"> <img class="img2" src="dice6.png" ...

When sending API data back to Vue from Express, the response is coming back as an empty

I am encountering an issue with my express app where I am trying to send data back from a third-party API to my front-end application. Despite being able to see the content in my express API, I am not receiving any results on the front end. Any suggestions ...

Unable to hear sound - JavaScript glitch

Spent countless hours trying to figure this out - Can't get the audio file to play when clicking an HTML element. var sound = document.querySelector(".soundfile"); function playAudio() { sound.play(); } document.querySelector(".btn-hold").addE ...

What steps do I need to take in order to transform this code into a MUI component complete with

Having some trouble converting my hero banner code to MUI in a React project. The styling is not coming out correctly. Here is the HTML code: <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120 ...