Does anyone know how to make a multiple select (see below HTML) sortable? Using either jQuery or Ext JS? By sortable, I mean that I can drag an item (an option) up or down to reposition it in the select control.
<select id="testing" multiple=multiple>
<option>First Option</option>
<option>Second Option</option>
<option>Third Option</option>
<option>Forth Option</option>
<option>5 Option</option>
<option>6 Option</option>
<option>7 Option</option>
</select>
This can be attached to text (freetagging) as well as to select. I does have drag_drop and remove_button plugins.
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/js/standalone/selectize.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/css/selectize.css" />
<script>
$(function() {
$('select').selectize({
plugins: ['remove_button', 'drag_drop']
});
});
</script><select multiple>
<option value ="1">One</option>
<option value ="2" selected>Two</option>
<option value ="3" selected>Three</option>
</select>
This can be attached to a select element and has an ordered option which then rewrites the order of the select options. So your selections are returned in the order you select them. Drag-and-drop is not possible though and will not be implemented.
You can't do it reliably with drag-and-drop. <select multiple> may be implemented using an OS select-list widget, which will not typically generate mouse events like the native HTML elements do.
You'd have to replace the <select> with a load of <div> analogues for it, which do provide sortability in the normal way whichever library/plugin you want to use for it does. It's a fair bit of bother to make an ersatz-<select> nicely accessible/usable/keyboardable though; most plugins don't really manage to fully.
The simpler alternative would be simply to have separate ‘Move up’/‘Move down’ buttons, which find and move the selected <option>s in the element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With