I have used select2 to select multiple options from a drop down, but is it possible for select2 to select the full optgroup?? What I want is when user select the option grou
One option for V 4.0.2 using a select element:
JS + JQuery:
$(document).ready(function() {
$('#source').select2();
$(document).on("click", ".select2-results__group", function(){
var groupName = $(this).html()
var options = $('#source option');
$.each(options, function(key, value){
if($(value)[0].parentElement.label.indexOf(groupName) >= 0){
$(value).prop("selected","selected");
}
});
$("#source").trigger("change");
$("#source").select2('close');
});
});
Fiddle: https://jsfiddle.net/un1oL8w0/4/