I have been trying without success to get multiselect to function as expected. I can wrap the multiSelect call like the following and it works, but for some reason if it is not wrapped like the immediate example code, it does not work.
(function ($) {
$(function () {
$('#mySelectList').multiSelect();
})
})(jQuery);
I could get over this annoyance if I could call $('#keep-order').multiSelect('select', 'whatIwant');
But calling the multiselect select does not work elsewhere due to the scope, if I understand correctly.
Here is what I right now, if it helps. To clarify, the below will work, except the bit marked with "does not work".
Here is the html loading scripts:
<link type="text/css" href="~/css/multiselect/multiselect.css" rel="stylesheet" />
<link type="text/css" href="~/css/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="~/Scripts/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="~/js/quicksearch/jquery.quicksearch.js"></script>
<script type="text/javascript" src="~/js/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="~/js/multiselect/multiselect.js"></script>
<script type="text/javascript" src="~/Scripts/myjavascript.js"></script>
Contents of myjavascript.js
// This is a combination of quicksearch and multiselect.
; (function ($) {
$(function () {
$('#mySelectList').multiSelect({
keepOrder: true,
selectableHeader: "<div class='searchTitle'>Select: Sap</div><input type='text' id='searchSelectable' class='search-input' autocomplete='off' placeholder='Search: Sap'>",
selectionHeader: "<div class='searchTitle'>Selection:</div><input type='text' class='search-input' autocomplete='off' placeholder='Search: Selection'>",
afterInit: function (ms) {
var that = this,
$selectableSearch = that.$selectableUl.prev(),
$selectionSearch = that.$selectionUl.prev(),
selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';
that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
.on('keyup', function (e) {
if (e.which === 40) {
that.$selectableUl.focus();
return false;
} else if (e.which === 86 && e.ctrlKey) { // Ctrl + V
// ############################################ //
// ######## The following does not work ######## //
// ############################################ //
$('#mySelectList').multiSelect('select', 'something');
});
$('#searchSelectable').val('');
return false;
}
});
that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
.on('keydown', function (e) {
if (e.which === 40) {
that.$selectionUl.focus();
return false;
}
});
},
afterSelect: function () {
this.qs1.cache();
this.qs2.cache();
},
afterDeselect: function () {
this.qs1.cache();
this.qs2.cache();
}
});
// Hide everything until multiselect does its thing
$("#hideReady").show();
})
})(jQuery);