Is there a way to exchange the chosen options between two bootstrap-vue multiple select boxes?

Is there a way to switch the selected options between two bootstrap-vue multiple select boxes? I am trying to create a UI similar to the image shown below but I am struggling with writing the method.

This is how I have written the template:

<template>
  <b-row
    align-v="center"
  >
    <b-col cols="5">
      <b-card header="A Multiple Select" no-body>
        <b-card-body>
          <b-overlay :show="selectedBusyFlag" opacity="0.6">
            <b-form-select
              v-model="inActiveSelected"
              :options="inActiveOptions"
              multiple
            ></b-form-select>
          </b-overlay>
        </b-card-body>
      </b-card>
    </b-col>
    <b-col cols="2">
      <b-row>
        <b-col align="center">
          <b-button
            variant="link"
            class="button-pattern-throw"
            @click="
              moveOptionsToSelect(
                inActiveSelected,
                inActiveOptions,
                activeSelected,
                activeOptions,
                'DIRECTION_001',
              )
            "
          >
            <i class="fas fa-arrow-circle-right"></i>
          </b-button>
        </b-col>
      </b-row>
      <b-row>
        <b-col align="center">
          <b-button
            variant="link"
            class="button-pattern-throw"
            @click="
              moveOptionsToSelect(
                activeSelected,
                activeOptions,
                inActiveSelected,
                inActiveOptions,
                'DIRECTION_002',
              )
            "
          >
            <i class="fas fa-arrow-circle-left"></i>
          </b-button>
        </b-col>
      </b-row>
    </b-col>
    <b-col cols="5">
      <b-card header="B Multiple Select" no-body>
        <b-card-body>
          <b-overlay :show="selectedBusyFlag" opacity="0.6">
            <b-form-select
              v-model="activeSelected"
              :options="activeOptions"
              multiple
            ></b-form-select>
          </b-overlay>
        </b-card-body>
      </b-card>
    </b-col>
  </b-row>
</template>
<script>
...
moveOptionsToSelect(selected1, option1, selected2, option2, direction) {
        const select1Model = selected1;
        const select1Option = option1;
        const select2Model = selected2;
        const select2Option = option2;
        if (direction === 'DIRECTION_001') {
          // select A to select B
        } else if (direction === 'DIRECTION_002') {
          // select B to select A
        }
    },
...
</script>

Even though I have created different paths based on the "direction string" in the "moveOptionsToSelect" function, the execution stops after that point.

I would appreciate any assistance!

Answer ā„–1

To manage the two select elements, I recommend using separate arrays for each. One approach is to remove an item from the first array and add it to the second array based on user interaction. It's important to make copies of the options in order to prevent immediate modification when switching between selections.

Answer ā„–2

By utilizing the following code snippet, I was able to resolve the issue.

After submitting my initial question, I formulated a new perspective and delved deeper into the problem. Subsequently, I drafted the necessary code modifications which led to successful resolution.

I trust that sharing this approach will benefit individuals encountering a similar challenge.

    rearrangeOptions(direction) {
      let movableObjects;
      if (direction === 'LTR') {
        movableObjects = this.inactiveOptions.filter(elm =>
          this.inactiveSelected.includes(elm.value),
        );

        this.inactiveOptions = this.inactiveOptions.filter(
          elm => !this.inactiveSelected.includes(elm.value),
        );
        this.inactiveSelected = [];

        this.activeOptions.push(...movableObjects);
      }
      else if (direction === 'RTL') {
        movableObjects = this.activeOptions.filter(elm =>
          this.activeSelected.includes(elm.value),
        );

        this.activeOptions = this.activeOptions.filter(
          elm => !this.activeSelected.includes(elm.value),
        );
        this.activeSelected = [];

        this.inactiveOptions.push(...movableObjects);
      }
    },

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

ES6: Using DataURI to provide input results in undefined output

In my current project, I am facing a challenge. I am attempting to pass image dataURI as an input from a url link to the image. To achieve this task, I know that I have to utilize canvas and convert it from there. However, since this process involves an &a ...

Show the contents of a JSON file using Vue

I have a JSON file containing some data that needs to be fetched and displayed in a component. In the actions of my Vuex store, I've implemented: async getTodos (context) { const todos = [] const response = await fetch('../../data/todos.jso ...

Initializing Angular variables

My Angular controller has a variable called $scope.abc. The backend I'm using is Sails. The initial value of $scope.abc can be set by the backend when the page is first generated. Once the page is displayed, the user may or may not change this value ...

Tips for creating a mandatory textarea input field

It's pretty straightforward - I have a textarea that is set to required, but it only alerts the user if you actually click inside the text area. If you try to submit without clicking inside, it won't prompt the alert. Take a look at this Fiddle ...

Animate failed due to the appending and adding of class

$('#clickMe').click(function() { $('#ticketsDemosss').append($('<li>').text('my li goes here')).addClass('fadeIn'); }); <link href="http://s.mlcdn.co/animate.css" rel="stylesheet"/> <script ...

Guide to placing the Drawer component beneath the AppBar in Material-UI

Exploring the capabilities of the Material UI drawer component, I'm looking to position the drawer below the appbar. My goal is to have the hamburger icon toggle the drawer open and closed when clicked: opening the drawer downwards without moving the ...

You cannot use a relative path when inserting an image tag in React

I am having an issue with my img tag not loading the desired image when using a relative src path in my React project. When I try: //import { ReactComponent } from '*.svg'; import React from 'react'; import firebase from "./firebas ...

When testing, Redux form onSubmit returns an empty object for values

Is it possible to pass values to the onSubmit handler in order to test the append function? Currently, it always seems to be an empty object. Test Example: const store = createStore(combineReducers({ form: formReducer })); const setup = (newProps) => ...

Remove webpack functions from the bundle

After following a comprehensive tutorial on bundling files with webpack and some additional online research, I successfully created a configuration file that organizes the modules in my library into the specified structure: dist/node/weather.min.js dist/we ...

Display the precise outcome for each division following a successful AJAX callback

Iā€™m facing a challenge in getting individual results for each item after a successful AJAX callback. Currently, I am able to retrieve results, but when there are multiple items, all displayed results are being added to each div instead of just the corres ...

How to retrieve the same value from multiple selections using Vanilla JavaScript and multiple select options?

Why do we consistently receive the same value and index when using the ctl key to select multiple options? document.querySelector('select').addEventListener('change', function(e) { console.log(this.selectedIndex) console.log(e.ta ...

Position the spinner in the center of the user's screen

I created my own spinner: '''' #spinner-bg-loading{ position: absolute; left: 50%; top: 25%; width: 80px; height: 80px; margin: -75px 0 0 -75px; border: 16px solid #FFFFFF; border-radius: 50%; border-top: 16px solid #1 ...

Set a unique class for several elements depending on a given condition

Is there a way to assign a color class based on the element's value without looping through all elements? Check out my jsfiddle HTML <div> <ul> <li class="MyScore">90</li> <li class="MyScore"> ...

Unable to call Ionic component function using ref in Vue3

I'm attempting to utilize the closeSlidingItems method of the IonList element in order to automatically close the sliding item after clicking a button that appears from behind once the item is slid to the right. My approach involved referencing IonLi ...

Google Sheets displaying blank values after submission via an AJAX call

I have been working on transferring data from my web app to a Google spreadsheet and I am encountering some issues. I followed the script provided by Martin Hawksey, which can be found here: https://gist.github.com/mhawksey/1276293 Despite setting everyth ...

Instructions on how to automatically navigate to a different tab upon clicking an <a> element on a separate webpage, and subsequently display the designated tab on that

I have a button on my home page that, when clicked, should open a specific tab section on another page. The button is located on one page and the tabs are on a different page. On the second page, I have multiple tabs but will only mention one here, which ...

Arranging Text and Images in HTML/CSS to Ensure Optimal Placement When the Window Size Changes

Hello fellow coders! I've recently started diving into the world of website development and I have a query regarding positioning elements and handling window resizing. Can anyone help me out? I'm trying to center an image, a message, and a passw ...

If a particular <td> element is present on the page, exhibit a unique <div>

I have a webpage with various HTML elements. <div class="alert">Your message was not sent.</div> <p class="pending">Email Pending</p> I would like to display the div.alert only if the p.pending is present. Is ...

Include the insertion button in the Tiny MCE Editor

Currently, I am in the process of developing my own plugin to integrate into the list of TinyMCE v4 plugins. So far, I have successfully added a button to the menu that opens a pop-up when clicked. In this pop-up, users can input data which is then added t ...

Inserting HTML content into a DIV with the help of jQuery

Looking for a solution with my index.html file. I want to load other HTML files into a DIV by clicking on buttons. Here's an example of what I'm trying to achieve: I've searched through various examples online, but none seem to work for ...