Multiple Select List
This is a sample of building a list based selector.
by Shawn Wood
HTML
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/additional-methods.min.js"></script>
<div class="container">
<form id="thresholdForm" class="form-horizontal" method="post">
<div class="row form-group required">
<div class="col-xs-12">
<label class="control-label">Reporting Thresholds</label>
<span class="thresholdMessage help-block"></span>
</div>
<div class="col-xs-12 thresholdContainer form-control list-striped">
<ul id="thresholdList" class="list-unstyled btn-group row" data-toggle="buttons">
<li class="btn btn-threshold col-xs-12" id="threshold1">
<input type="checkbox" name="threshold1"/>
<div class="col-xs-6 text-left thresholdCell">
<span class="glyphicon glyphicon-unchecked"></span>
<span class="badge">1</span>
<strong>Description:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="col-xs-6 text-left thresholdCell">
<strong>Adjudicative Guidelines:</strong>
<ul class='list-unstyled'><li>A: Lorem ipsum dolor</li><li>B: Consectetur Adipiscing</li><li>E: Commodo Consequat</li><li>I:...
CSS
.thresholdContainer{
height:300px;
overflow-y: scroll;
border: 1px solid #000;
}
.list-striped > ul > li:nth-of-type(odd) {
background-color: #f9f9f9;
}
.list-striped > ul > li:nth-of-type(odd):active,
.list-striped > ul > li:nth-of-type(odd).active {
background-color: #3A4E6E;
}
.list-striped > ul > li:nth-of-type(even) {
background-color: #ffffff;
}
.list-striped > ul > li:nth-of-type(even):active,
.list-striped > ul > li:nth-of-type(even).active {
background-color: #3A4E6E;
}
.btn-threshold:focus {
color: #fff;
background-color: #286090;
border-color: #122b40;
border 3px;
outline: thin dotted #FF0000;
outline: 15px auto -webkit-focus-ring-color;
outline-offset: -18px;
}
.btn-threshold:hover {
color: #000;
background-color: #286090;
/*border-color: #204d74;*/
}
.btn-threshold:active,
.btn-threshold.active {
background-image: none;
/*font-weight:bold;*/
font-style:italic;
color:white;
outline: 0;
-webkit-box-shadow: inset 5px 0px 5px 5px rgba(0, 0, 100, .125);
box-shadow: inset 5px 0px 5px 5px rgba(0, 0, 100, .125);
}
.thresholdCell{
white-space: normal;
}
JavaScript
//
$(document).ready(function() {
$('.btn-threshold').on('click', function(){ if($(this).hasClass("active")){$(this).find('.glyphicon').removeClass("glyphicon-check").addClass("glyphicon-unchecked");}else{$(this).find('.glyphicon').removeClass("glyphicon-unchecked").addClass("glyphicon-check");}setTimeout(function(){countUnchecked()}, 100);});
//$('.thresholdMessage').text($("#thresholdList li").length);
});
$('#checkValid').on('click', function(){countUnchecked();});
//function countUnchecked() {$('.thresholdMessage').text($("#thresholdList li.active").length);}
function countUnchecked() {if($("#thresholdList li input:checked").length < 1){$('.thresholdMessage').text("You must select a Reporting Threshold");$('.thresholdContainer').parentsUntil('form-group').removeClass('has-success').addClass('has-error');}else{$('.thresholdMessage').text("");$('.thresholdContainer').parentsUntil('form-group').removeClass('has-error').addClass('has-success');}}
jQuery.validator.setDefaults({debug:true,success:"valid"});