Skip to content

Instantly share code, notes, and snippets.

Created June 23, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/64372717ba83a551f768 to your computer and use it in GitHub Desktop.
Save anonymous/64372717ba83a551f768 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/qabumuvevo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<link href="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<select style="width: 300px;" multiple="multiple">
<!-- <optgroup label="Swedish Cars">-->
<option>red</option>
<option>green</option>
<!-- </optgroup> -->
<option>blue</option>
<option>yellow</option>
<option>white</option>
<option>black</option>
</select>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<script id="jsbin-javascript">
$("select").select2({
closeOnSelect: false,
templateResult: function (data) {
var $res = $('<span></span>');
var $check = $('<input type="checkbox" />');
$res.text(data.text);
if (data.element) {
$res.prepend($check);
$check.prop('checked', data.element.selected);
}
return $res;
}
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<select style="width: 300px;" multiple="multiple">
<\!-- <optgroup label="Swedish Cars">-->
<option>red</option>
<option>green</option>
<\!-- </optgroup> -->
<option>blue</option>
<option>yellow</option>
<option>white</option>
<option>black</option>
</select>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"><\/script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"><\/script>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">$("select").select2({
closeOnSelect: false,
templateResult: function (data) {
var $res = $('<span></span>');
var $check = $('<input type="checkbox" />');
$res.text(data.text);
if (data.element) {
$res.prepend($check);
$check.prop('checked', data.element.selected);
}
return $res;
}
});</script></body>
</html>
$("select").select2({
closeOnSelect: false,
templateResult: function (data) {
var $res = $('<span></span>');
var $check = $('<input type="checkbox" />');
$res.text(data.text);
if (data.element) {
$res.prepend($check);
$check.prop('checked', data.element.selected);
}
return $res;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment