Skip to content

Instantly share code, notes, and snippets.

@Arsey
Created December 28, 2013 10:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arsey/8157974 to your computer and use it in GitHub Desktop.
Save Arsey/8157974 to your computer and use it in GitHub Desktop.
modified to support group choosing createOptionValue function from bootstrap-multiselects by David Stutz(https://github.com/davidstutz/bootstrap-multiselect)
// Will build an dropdown element for the given option.
createOptionValue : function(element,groupId) {
if ($(element).is(':selected')) {
$(element).attr('selected', 'selected').prop('selected', true);
}
// Support the label attribute on options.
var label = $(element).attr('label') || $(element).text();
var value = $(element).val();
var inputType = this.options.multiple ? "checkbox" : "radio";
var $li = $('<li><a href="javascript:void(0);"><label class="' + inputType + '"><input type="' + inputType + '" /></label></a></li>');
var selected = $(element).prop('selected') || false;
var $checkbox = $('input', $li);
$checkbox.val(value);
$checkbox.attr('data-group-id',groupId);
if (value == this.options.selectAllValue) {
$checkbox.parent().parent().addClass('multiselect-all');
}
$('label', $li).append(" " + label);
$('.multiselect-container', this.$container).append($li);
if ($(element).is(':disabled')) {
$checkbox.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled');
}
$checkbox.prop('checked', selected);
if (selected && this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass);
}
},
@Arsey
Copy link
Author

Arsey commented Dec 28, 2013

ware modified function arguments(added groupId argument) and on line 17 added attribute for group identification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment