views:

36

answers:

2

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>
+1  A: 

jQuery UI has functions for making things sortable. See http://jqueryui.com/demos/sortable/.

tomit
Right, so how do you do it? The examples only show that it is possible for <ul> and <div>, but <select multiple> is a bit different.
Moses Ting
A: 

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.

bobince
Yes, I thought about simply including a set of "Move up/Move down' buttons. But I'm trying to not go down that route because it's a negative impact on usability. Unless the up/down buttons are shown within the option item, then it's a little easier for the user.
Moses Ting
I was afraid that I need to go down the <div> route in order to make a list of items sortable, but I don't think I have a choice here.
Moses Ting