How to create an association form (Picklist) in modal?

Asked

Viewed 676 times

4

How to make the screen below in modal. inserir a descrição da imagem aqui

Remembering that the boxes are multiple selection, and how to do that by clicking the button Associar > move to the right column the values I selected on the left and vice versa when clicking on < Desassociar? It can be in jQuery or even Javascript.

  • The question of the title has no context with the doubt of the text explained. See here how to make a modal form in html using bootstrap.

  • What I want is to click on a button on another page of mine and open this modal, like this: I click on the form button on the page start.html and open this modal placed in the comment.html

  • I also wanted to know how to organize this way by booststrap as it is very disorganized @Thiagolunardi

1 answer

5


The whole process is quite simple, first you need to have two select’s with the Multiple attribute and two buttons to carry out the associations, all you will do is take the selected item and add in the other select and then remove the option from the previous!

In bootstrap you can use form-control to give an additional formatting.

Example:

var associar = $("#associar");
var desassociar = $("#desassociar");
var permissoes = $("#permissoes");
var minhasPermissoes = $("#minhasPermissoes");


associar.click(function() {
  var selecionado = permissoes.find('option:selected');
  minhasPermissoes.append('<option>' + selecionado.text() + '</option>');
  selecionado.remove();
});

desassociar.click(function() {
  var selecionado = minhasPermissoes.find('option:selected');
  permissoes.append('<option>' + selecionado.text() + '</option>');
  selecionado.remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<div class="container">
  <div class="row">
    <div class="col-md-6">
      <label>Permissões</label>
      <select id="permissoes" class="form-control" multiple>
        <option>Clientes</option>
        <option>Boletos</option>
        <option>Usuários</option>
        <option>Configurações</option>
      </select>
    </div>
    <div class="col-md-6">
      <label>Minhas Permissões</label>
      <select id="minhasPermissoes" class="form-control" multiple>
      </select>
    </div>
  </div>
  <br>
  <button id="associar" class="btn btn-primary">Associar</button>
  <button id="desassociar" class="btn btn-primary">Desassociar</button>

</div>

See also working on jsfiddle

To add in a modal is very simple too, the bootstrap documentation itself has excellent examples of this.

See working with modal on jsfiddle

Documentation Bootstrap-Modal

You can also use a plugin I developed, just include the pickList.js create a div and call $("#pickList").pickList();

Github - Documentation

Example jsfiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.