Tips on utilizing radio button prepend for selecting one input from multiple options

According to the bootstrap-vue documentation (based on bootstrap 4):

<b-input-group>
  <b-input-group-prepend is-text>
    <input type="radio" aria-label="Radio for following text input">
  </b-input-group-prepend>
  <b-form-input aria-label="Text input with radio button"></b-form-input>
</b-input-group>

Here is the output of this input:
https://i.sstatic.net/nHCgW.png

I am looking to create a component that allows users to choose one of multiple values based on the input above. For example,

selectedValue: null,
compareOptions: [{text: "Value1", value: option1}, {text: "Value2", value: option2}] 

However, the documentation mentions:

Note: you must use native radio and checkbox inputs, as and include additional markup not required in input groups.

How can I utilize the code provided in the documentation to set up a v-model and options in order to achieve the desired functionality.

Answer №1

If someone finds it intriguing, the solution is:
Child Component

<template>
  <b-container fluid>
    <b-form-group
      :label="formLabel"
      class="mb-1"
      label-class="text-center">
      <b-row>
        <b-col class="pl-2 pr-1">
          <b-input-group
            size="sm"
            сlass="mb-1">
            <b-input-group-prepend is-text>
              <input
                v-model="selectedValue"
                :value="oldValue"
                type="radio"
                @change="sendSelected">
            </b-input-group-prepend>
            <b-form-input
              :value="oldValue"
              @input="changeValue('old', $event)" />
          </b-input-group>
        </b-col>
        <b-col class="pl-1 pr-2">
          <b-input-group
            size="sm"
            class="mb-1">
            <b-input-group-prepend is-text>
              <input
                v-model="selectedValue"
                :value="newValue"
                type="radio"
                @change="sendSelected">
            </b-input-group-prepend>
            <b-form-input
              :value="newValue"
              @input="changeValue('new', $event)" />
          </b-input-group>
        </b-col>
      </b-row>
    </b-form-group>
  </b-container>
</template>

<script>
export default {

  props: {
    value: {
      type: Object,
      required: true
    }
  },

  data () {
    return {
      selectedValue: null
    }
  },

  computed: {
    newValue () {
      return this.value.new
    },

    oldValue () {
      return this.value.old
    },

    formLabel () {
      return this.value.label
    }
  },

  created () {
  },

  methods: {
    sendSelected () {
      this.$emit('change', this.selectedValue)
    },

    changeValue (path, event) {
      this.selectedValue = null
      this.emitMutationEvent(path, event) //custom event
    }
  }
}
</script>  

Parent Component

<template>
  <b-container fluid>
    <compare-component
      v-for="documentField in documentFields"
      :key="documentField.id"
      :value="documentField"
      @change="setSelectedValue(documentField, ...arguments)"
      @mutate="editOriginValues(documentField, ...arguments)" />
  </b-container>
</template>

<script>
import CompareComponent from './CompareComponent'

export default {
  components: {
    CompareComponent
  },

  mixins: [PropMutationEventMixin],

  data () {
    return {
      reviewDocument: null,
      newSessionDocument: null,
      oldSessionDocument: null,
      documentFields: [
        {
          id: 1,
          old: 'old text 1',
          new: 'new text 1',
          label: 'text1',
          selected: ''
        },
        {
          id: 2,
          old: 'old text 2',
          new: 'new text 2',
          label: 'text 2',
          selected: ''
        },
        {
          id: 3,
          old: 'old text  3',
          new: 'new text 3',
          label: 'text 3',
          selected: ''
        }
      ]
    }
  },

  methods: {
    setSelectedValue (documentField, event) {
      documentField.selected = event
    },

    editOriginValues (documentField, path, newValue) {
      documentField[path] = newValue
    }
  }
}
</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

During the deployment of a ReactJS app, webpack encounters difficulty resolving folders

While developing my ReactJS app, everything ran smoothly on localhost. However, I encountered some serious issues when I tried to deploy the app to a hosting service. In my project, I have a ./reducers folder which houses all of my reducers. Here is the s ...

The issue with Jquery Lightbox/Modal doubling upon clicking

Having just started with jQuery, I've encountered an issue with my Gallery Lightbox/Modal. Whenever I click on a thumbnail, the modal reopens itself and I'm unsure where to set a reset. Any help would be greatly appreciated. jQuery(function($) { ...

The Nuxt auth module fails to update the user's loggedin status within the store state

Currently, I am implementing Authentication functionality using the Nuxt Auth Module. My frontend is built on Nuxt Js, while my backend is running Laravel 5.7 In nuxt.config.js, I have configured the auth settings as follows: auth: { strategies: { ...

Encountering NgRx Select Issues While Trying to Access Nested Properties

I've encountered TypeErrors while using NgRx select functions to access nested properties. In my app.module.ts, I have configured the root store as follows: StoreModule.forRoot({ app: appReducer }), The selectors causing errors are related to some ...

Strategies for choosing the perfect GIF to showcase in a React JS project

Hey everyone, I'm completely new to working with react JS and I've encountered a problem. I have a task where I need to display GIFs when a button is clicked, but I'm struggling to select a specific GIF. Can anyone provide some guidance on f ...

Sorting an array of objects based on a combination of numbers and special characters

I'm currently facing an issue with sorting an array of objects based on the dimension property, which consists of number intervals and special characters. Here's a snippet of the data I have: let data = [ { "soldTickets": 206, "soldR ...

Issue with scrolling in Droppable container on JQuery UI interface

I've encountered an issue with JQuery UI. In my code snippet, I can drag elements onto fields and when hovering over a field, it gets highlighted in green. However, I recently added the functionality to scroll while dragging. Now, I can scroll up and ...

Issue with positioning in Excanvas VML

After struggling through the implementation of excanvas on ie8, I managed to sort out the dynamic element issue. The once hidden elements are now rendering properly throughout most of the app, but just when it seemed like all was going well, another proble ...

"Optimize Magellan Sidebar for Mobile Devices by Relocating it to the Bottom of the Page

After spending a week working with Foundation 5 framework, I'm curious if there is a straightforward way to make my magellan sidebar shift to the bottom of the page when viewed on mobile or tablets. <div data-magellan-expedition="fixed"> <di ...

How can I isolate the CSS of my Vue application from the rest of the website?

I am currently working on developing a unique "plugin" that will feature a user interface to be integrated into various vendor websites. This particular plugin is designed to be CMS agnostic, and due to SEO concerns, I am unable to utilize an iframe. My go ...

Is it possible to activate multiple animations simultaneously within a single div using UIKit?

I recently started developing a to-do web application and was looking to enhance its appearance with some animations using UIKit. Currently, I have an animation that toggles when the todo-items are brought into view: <div class="todo-items uk-anim ...

Jquery ajax is failing to achieve success, but it is important not to trigger an error

My jQuery ajax request seems to be stuck in limbo - it's not throwing an error, but it also never reaches the success function. This is how my code looks: function delete() { $("input[name='delete[]']:checked").each(function() { ...

Customizing the date format in Vuetify's Datepicker

I am currently using a Vuetify Datepicker component in my project: <v-menu v-model="menu1" :close-on-content-click="false" max-width="290" > <template v-slot:activator="{ on }"> <v-text-field v-model="editedItem. ...

Strip newline characters from information in AngularJS

What is the recommended approach for detecting and formatting the "\n\n" line breaks within text received from the server before displaying it? Check out this Fiddle: http://jsfiddle.net/nicktest2222/2vYBn/ $scope.data = [{ terms: 'You ...

What is the best method for converting a plist file into a json file?

Is there a way to convert an existing plist file into a JSON file using one of the following programming languages: JavaScript, Java, Objective-C, Python, or Ruby? Any suggestions on how to do this? ...

The issue with the background color being transparent is not being resolved

Looking for help with a Bootstrap 4 issue I'm experiencing. I have set a fixed background image using CSS on a webpage, and I want to stack multiple <div> elements one after the other with transparent spacing between them. The goal is to allow p ...

The categorizing and organizing of arrays

My goal is to create a messaging application where users can view a list of their recent messages, along with a preview of the latest message received/sent, before selecting a conversation. However, I'm facing an issue with my script that displays all ...

Overriding the Ajax URL

During an AJAX request in a Rails app triggered by onchange event, I am encountering an issue with the URL being called. The function for the request is a simple PUT operation: function quantityChange(id, val) { $.ajax({ url: 'cart_items/ ...

The error of "Uncaught ReferenceError" is being triggered by the use of `process?.env?

A bug was discovered in our front-end code related to the following snippet: <span style={{ color: 'red' }}>{process?.env?.REACT_APP_HEADER_SUFFIX ?? ''}</span> The bug triggered the following error message: Uncaught Refere ...

pressure exerted on the body

Recently, I've been working on a project for the website . One of the main issues I've encountered is that the <body> element is consistently 20px lower than it should be at the top. This has led to visible problems with the background grad ...