.dual-list .list-group {
margin-top: 8px;
}
.list-left li, .list-right li {
cursor: pointer;
}
.list-arrows {
padding-top: 100px;
}
/*Changed to use anchor instead of button*/
.list-arrows a {
margin-bottom: 20px;
}
$(document).ready(function () {
//Finds and ammends all boxes in righthand list with hidden inputs based off
// data-field and data-values for name and value respectively
$('.dual-list.list-right').find('li').each(
function () {
$(this).append($('<input>').attr({
type: 'hidden',
name: $(this).attr('data-field'),
value: $(this).attr('data-value')
}))
}
)
})
$(function () {
$('body').on('click', '.list-group .list-group-item', function () {
$(this).toggleClass('active');
});
//button changed to an anchor to prevent messing around with the buttons
//to prevent them submitting a form.
$('.list-arrows a').click(function () {
var $button = $(this), actives = '';
if ($button.hasClass('move-left')) {
//Goes up the dom to find the current list it's working inside of,
//This allows multiple lists to be used on the same page without clashes
actives = $(this).parent().parent().find($('.list-right ul li.active'));
//Again finds the parent div of the button
actives.clone().appendTo($(this).parent().parent().find('.list-left ul'));
actives.remove();
//Removes any cloned inputs from those just moved accross.
$(this).parent().parent().find($('.list-left ul li.active')).find($("input[type='hidden']")).remove();
} else if ($button.hasClass('move-right')) {
actives = $(this).parent().parent().find($('.list-left ul li.active'));
//Adds in the input field
actives.append($('<input>').attr({
type:'hidden',
name: actives.attr('data-field'),
value: actives.attr('data-value')
}))
actives.clone().appendTo($(this).parent().parent().find('.list-right ul'));
actives.remove();
}
});
$('.dual-list .selector').click(function () {
var $checkBox = $(this);
if (!$checkBox.hasClass('selected')) {
$checkBox.addClass('selected').closest('.well').find('ul li:not(.active)').addClass('active');
$checkBox.children('i').removeClass('glyphicon-unchecked').addClass('glyphicon-check');
} else {
$checkBox.removeClass('selected').closest('.well').find('ul li.active').removeClass('active');
$checkBox.children('i').removeClass('glyphicon-check').addClass('glyphicon-unchecked');
}
});
$('[name="SearchDualList"]').keyup(function (e) {
var code = e.keyCode || e.which;
if (code == '9') return;
if (code == '27') $(this).val(null);
var $rows = $(this).closest('.dual-list').find('.list-group li');
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function () {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
});