snippet

Select from dual list by Deyson Bejarano


Tags: Bootstrap Snippet Html Css list

The MIT License (MIT)

Copyright (c) 2017 Deyson Bejarano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
.v-center { min-height:200px; display: flex; justify-content:center; flex-flow: column wrap; } $('.add').click(function(){ $('.all').prop("checked",false); var items = $("#list1 input:checked:not('.all')"); var n = items.length; if (n > 0) { items.each(function(idx,item){ var choice = $(item); choice.prop("checked",false); choice.parent().appendTo("#list2"); }); } else { alert("Choose an item from list 1"); } }); $('.remove').click(function(){ $('.all').prop("checked",false); var items = $("#list2 input:checked:not('.all')"); items.each(function(idx,item){ var choice = $(item); choice.prop("checked",false); choice.parent().appendTo("#list1"); }); }); /* toggle all checkboxes in group */ $('.all').click(function(e){ e.stopPropagation(); var $this = $(this); if($this.is(":checked")) { $this.parents('.list-group').find("[type=checkbox]").prop("checked",true); } else { $this.parents('.list-group').find("[type=checkbox]").prop("checked",false); $this.prop("checked",false); } }); $('[type=checkbox]').click(function(e){ e.stopPropagation(); }); /* toggle checkbox when list group item is clicked */ $('.list-group a').click(function(e){ e.stopPropagation(); var $this = $(this).find("[type=checkbox]"); if($this.is(":checked")) { $this.prop("checked",false); } else { $this.prop("checked",true); } if ($this.hasClass("all")) { $this.trigger('click'); } });