views:

250

answers:

2

I have a picklist web interface: a pair of select elements with a pair of buttons (a left-pointing arrow and a right-pointing arrow) between them. Users can move items between the two columns by, eg, selecting one of options in the left column and clicking on the right-pointing arrow.

Now I have an enhancement request: someone wants to be able to drag-and-drop items between the two columns instead of clicking a button. The problem with my initial two-select-box setup is that as soon as I click one of the highlighted options to initiate a drag, all of the other selected options are deselected. Using jQuery, I've attached mousedown event handlers to both the select boxes and each individual option that just call preventDefault() on the event object, but this isn't sufficient. On Firefox 3 the clicked-on option loses focus immediately, but all other options are still deseleted, and on IE6 (which I regrettably still have to support) it makes no difference at all.

So I thought I could maybe create a reasonable facsimile of a select box using list elements or divs or something. I can create something reasonable-looking that works on Firefox, but on IE6, if I shift-click on an element of my pseudo-select object (in order to select a range of options), IE selects all of the text between where I click and the last place I clicked. Again, I've attached preventDefault-ing mousedown, mouseup, and click handlers to all of the elements involved, but it doesn't help.

I've even tried overlaying transparent divs over both my original select boxes and my pseudo-select objects, thinking to intercept mouse clicks and manage the selections manually, but I can't make it work on IE. If I use a select box, I can't prevent clicks from changing the selection, and if I use text that just looks like a select element, I can't prevent it from selecting a range of text on a shift-click.

Is there some general solution, or am I just out of luck?

A: 

Check out the Jquery UI Sortable with two connected sortable lists : http://jqueryui.com/demos/sortable/#connect-lists

It's just:

    $('.selector').sortable({ connectWith: '.otherlist' });
powtac
Thanks for the pointer! It's not quite what I need, since I have to be able to allow users to select multiple options (potentially hundreds) and move them all at once, but in poking around the page source I noticed an HTML attribute "unselectable" that I'd never heard of before. It's MS-only and prevents text from being selected, which might be just the thing to get my pseudo-select object working correctly on IE.
Sean
I had a sortable list and an empty sortable list, with drag and drop the users where able to fill the empty list with items from the other list. Maybe this kind of UI helps?
powtac
A: 

I ended up going with the "unselectable" attribute.

Sean