Searching for an AngularJS and Bootstrap Dual Listbox Solution

I need a component like this to integrate into my project:

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

I am hoping to add it using npm.

However, I have tried some of the examples available but faced issues (encountered exceptions or only found bower instead of npm).

The following are the examples I experimented with.

Any suggestions for one that works well with AngularJs, Bootstrap, and can be installed via npm?

Answer №1

Here is a potential solution for your needs: Dual list Box

app.js

angular.module('plunker', [])
  .controller('MainCtrl', function($scope, utilities) {
    $scope.list1 = [],
      $scope.list2 = [];

    utilities.insertData($scope.list1, 5);

  })
  .factory('utilities', function Utils() {
    return {
      insertData: function(list, numItems) {
        for (var i = 0; i < numItems; i++) {
          list.push({
            id: i + 1,
            title: 'item' + (i + 1)
          });
        }
      },
      getIndexesFromList: function(list) {
        var newList = [];
        for (var i in list) {
          if (typeof list[i].id === "number" && newList.indexOf(list[i].id) === -1) newList.push(list[i].id)
        }
        return newList;
      },
      getAllSelectedItems: function(list) {
        var newList = [];
        newList = list.filter(function(el) {
          return el.active === true;
        });
        return newList;
      },
      addListIfNotExists: function(list2, newListToAppend) {
        var indexes = this.getIndexesFromList(list2);
        var newList = [];
        for (var i in newListToAppend) {
          if (indexes.indexOf(newListToAppend[i].id) === -1) list2.push(newListToAppend[i])
        }
        return list2;
      }
    }
  })
  .directive('dualList', function(utilities) {

    function _controller($scope) {
      $scope.selectAllItems = function(list, checked) {
        list.map(function(item) {
          item.active = checked
          return item;
        });
      };
      $scope.getAllChosenItems = function(list) {
        return utilities.getAllChosenItems(list);
      }
      $scope.moveItemToRightList = function() {
        var newListToAppend = $scope.list1.filter(function(el) {
          if (el.active === true) {
            el.active = false;
            return el;
          }
        });
        if (newListToAppend.length > 0) {
          $scope.list1 = $scope.list1.filter(function(el) {
            return utilities.getIndexesFromList(newListToAppend).indexOf(el.id) === -1;
          });
          $scope.list2 = utilities.addListIfNotExists($scope.list2, newListToAppend);
          if ($scope.list1.length === 0) $scope.checked1 = false;
        }

      };
      $scope.moveItemToLeftList = function() {
        var newListToAppend = $scope.list2.filter(function(el) {
          if (el.active === true) {
            el.active = false;
            return el;
          }
        });
        if (newListToAppend.length > 0) {
          $scope.list2 = $scope.list2.filter(function(el) {
            return utilities.getIndexesFromList(newListToAppend).indexOf(parseInt(el.id)) === -1;
          });
          $scope.list1 = utilities.addListIfNotExists($scope.list1, newListToAppend);
          if ($scope.list2.length === 0) $scope.checked2 = false;
        }

      };
    }
    return {
      restrict: "E",
      scope: true,
      controller: _controller,
      templateUrl: "dualList.html"
    };
  });

dualList.html

<div class="container">
  <br />
  <div class="row">
    <div class="dual-list list-left col-md-5">
      <div class="well text-right">
        <div class="row">
          <div class="col-md-3">
            <div class="checkbox">
              <label>
                <input type="checkbox"
                       ng-model="checked1"
                       ng-click="selectAllItems(list1, checked1)">
                    All {{getAllChosenItems(list1).length}}/{{list1.length}}
              </label>
            </div>
          </div>
          <div class="col-md-9">
            <div class="input-group">
              <span class="input-group-addon glyphicon glyphicon-search"></span>
              <input type="text"
                     name="SearchDualList"
                     ng-model="search1"
                     class="form-control"
                     placeholder="search" />
            </div>
          </div>
        </div>
        <ul class="list-group">
          <a class="list-group-item"
             href=""
             data-id="{{item.id}}"
             ng-click="item.active = !item.active"
             ng-class="{active: item.active}"
             ng-repeat="item in list1|filter: search1">{{item.title}}</a>
        </ul>
        <p ng-if="(list1 | filter:search1).length == 0">No Data</p>
      </div>
    </div>
    <div class="list-arrows col-md-1 text-center">
      <button ng-click="moveItemToLeftList()"
              class="btn btn-default btn-sm move-left">
        <span class="glyphicon glyphicon-chevron-left"></span>
      </button>
      <button ng-click="moveItemToRightList()"
              class="btn btn-default btn-sm move-right">
        <span class="glyphicon glyphicon-chevron-right"></span>
      </button>
    </div>
    <div class="dual-list list-right col-md-5">
      <div class="well">
        <div class="row">
          <div class="col-md-3">
            <div class="checkbox">
              <label>
                <input type="checkbox"
                       ng-model="checked2"
                       ng-click="selectAllItems(list2, checked2)">
                    All {{getAllChosenItems(list2).length}}/{{list2.length}}
              </label>
            </div>
          </div>
          <div class="col-md-9">
            <div class="input-group">
              <span class="input-group-addon glyphicon glyphicon-search"></span>
              <input type="text"
                     name="SearchDualList"
                     ng-model="search2"
                     class="form-control"
                     placeholder="search" />
            </div>
          </div>
        </div>
        <ul class="list-group">
          <a class="list-group-item"
             href=""
             data-id="{{item.id}}"
             ng-click="item.active = !item.active"
             ng-class="{active: item.active}"
             ng-repeat="item in list2|filter: search2">{{item.title}}</a>
        </ul>
        <p ng-if="(list2 | filter:search2).length == 0">No Data</p>
      </div>
    </div>
  </div>
</div>

index.html

<!DOCTYPE html>
<html ng-app="plunker">
  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="https://code.angularjs.org/1.3.0/angular.js"></script>
    <link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
    <link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" />
    <link data-require="font-awesome@*" data-semver="4.3.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />
    <script>
      document.write('<base href="' + document.location + '" />');
    </script>
    <link rel="stylesheet" href="style.css" />
    <script src="app.js"></script>
  </head>
  <body ng-controller="MainCtrl">
    <dual-list data-list1="list1" data-list2="list2"></dual-list>
  </body>
</html>

style.css

.dual-list .list-group {
    margin-top: 8px;
}
.list-arrows {
    padding-top: 100px;
}
.list-arrows button {
    margin-bottom: 20px;
}
.list-group-item.active, .list-group-item.active:hover, .list-group-item.active:focus {
  border-color: white;
}
.input-group-addon {
  top: 0;
}

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

Issues with the AngularJS select directive when used with the option element

This specific case appears to be fairly straightforward, but for some reason I am encountering difficulties in getting it to function properly. I prefer not to utilize ng-options since it is incompatible with select2, a plugin that I intend to incorporate ...

Guide on integrating browserify into your node.js project as a dependency

I have a node.js application that relies on browserify being accessible via the command line for a shell script. Is there a way to ensure it is available within the application without needing my users to manually install it using npm install? ...

How can I send a Vue.js object to a Laravel controller?

I am working with a Vue component that includes an object like this - dataObj = [{id:1,name:'sanaulla'},{id:1,name:'parvez'}] When I try to send a post request to the Laravel Controller using the following code - axios.post("/api/ ...

Tips on updating a specific value within an element stored in an array

I'm currently in the process of setting up a table where each row contains unique values. Using a for loop, I am able to generate these rows and store them in an array. Now, my question arises when I consider modifying a particular value with the id " ...

Developing dynamic checkbox components using jQuery - unusual behavior in Internet Explorer

I am dynamically creating checkbox elements using jQuery and appending them to a specified node as shown below var topics = ['All','Cat1','Cat2']; var topicContainer = $('ul#someElementId'); $.each( topics, functio ...

What steps should I take to pinpoint the fundamental mistake in my webpage dedicated to clocks?

Exploring an intriguing clock project that utilizes ancient timekeeping methods found at . Recently encountered a puzzling error in Chrome, where it claims to be unable to call a method on undefined. Strangely enough, the error message is not located near ...

React JS server conditional response malfunctioning

I've been facing issues with receiving a conditional response from an Express server for a React application. Check out the server-side code below: app.get('/api/checklogin', (req, res) => { var val = req.session.user ? false : tru ...

"Enhancing security with Spring, managing admin roles through a gateway, and

Currently, I have implemented gateway-based authentication within Spring Security. The user's credentials are authenticated against the database. After successful authentication, the user is routed to the UI microservice through Zuul. However, when an ...

Altering a Common Variable Across Several AngularJS Directives

Check out this jsfiddle I created: http://jsfiddle.net/noahgoodrich/CDwfL/1/ I've developed a collection of directives to control and manipulate navigation tabs. Strangely, when I try to close a tab, it initially removes the correct array element, b ...

The onChange method in React is failing to execute within the component

I am having trouble overriding the onChange method in a component. It seems like the method is not triggering on any DOM events such as onChange, onClick, or onDblClick. Below are the snippets of code where the component is rendered and the component itsel ...

Utilizing Jquery to locate a specific word within a sentence and then appending a span element around

I need help fixing a function that is supposed to find a specific word in a sentence and add a span element around it. Here is the code I have so far, but for some reason it's not working as expected. Can anyone spot the mistake? Thank you! ...

`How can I trigger a Child Component method to refresh upon clicking a Button in the Parent Component using Vue JS?`

In a form field within the Parent Component, there is a submit button along with a select option. When the User changes the select option, it should pass that value to trigger a method/function in the child component. I want the child function to be automa ...

Is there a way to achieve element scrolling similar to scrollLeft within a scrollable container without using JavaScript

Looking for a CSS Solution: Is there a way to achieve element.scrollLeft functionality in CSS without using javascript? I want to pre-scroll a scrollable container. Situation Overview: I have a scrollable container that houses various items. Some instanc ...

Would it be unwise to send an AJAX post request every two seconds?

Is it frowned upon or risky to use an AJAX $.post call (with jQuery) to a php file in order to update a specific parameter or number? $.post(file.php, {var:var}, function(data){ // do something }, json); In this scenario, only one user on a single page w ...

When utilizing "reques" in Node.js code, the parameter response.timings may be found to be undefined

The code I created in node.js is giving me trouble - for some reason, response.timing is showing up as undefined. Any idea what could be causing this issue? const request = require("request"); request.get({ time : true, url : 'https://www.bbc.com ...

Buttons in HTML function properly on desktop but are ineffective on mobile devices

My website is almost complete, but I am facing some challenges with the mobile version. All buttons that use JavaScript are not functioning properly, whereas buttons with simple links work perfectly fine. This issue doesn't occur on Chrome when using ...

In ReactJS, the function 'composeEnhancers' is not recognized

I encountered the following error in my code: TypeError: composeEnhancers is not a function const store = createStore(rootReducer, composeEnhancers( applyMiddleware(thunk) )); I am puzzled because I just copied my ReactJS instructor's code and ...

Java script pop-up notifications always show up

This Text Goes Above the Form <?php require_once "core-admin/init-admin.php"; if( !isset($_SESSION['admin_username']) ){ $_SESSION['msg'] = 'page cannot be opened'; header('Location:admin_login.php&ap ...

Retrieving the ID from the element that was clicked

Here is a code snippet that allows for the changing of color and text when an href link is clicked. /* Function to change the color of the button upon click */ function changeColor(element) { alert(element.target.id); if (element.innerHTML == "Selec ...

Tips for troubleshooting the error message "Unable to access 'module' property of undefined" in AngularJS?

When I run the script test.bat in console, I encounter this error: Error: Uncaught TypeError - Cannot read property 'module' of undefined Chrome version 48.0.2564 (Windows 7) I am currently using Windows 7 and Angular Seed for my project. ...