How to produce a Gmail-style checkbox selection interface?
May 20, 2006 2:07 AM
Subscribe
Does anyone know how it's possible to produce an interface for checkbox selection like the one in
Gmail? Namely, where you can hold down shift and click the first and last items in a list, and it'll automatically select all the ones in between. Is it possible with simple JavaScript without having to use AJAX or other fancy-pants technology...
posted by tommorris to computers & internet (8 comments total)
The two most important things to look at when determining whether a shift-selection will be "check" or "uncheck" are the direction (based on the last selection) and the checked/unchecked status of the element you're clicking on. If you have a group selected, then click on an unchecked box at the other end of your selection, they will all be checked (since the checked status of the last box is false). If the checked status of the last item were instead true, it would unselect the items.
There's actually a bug in their selection model, if you play around with it: it appears that the last checked box becomes the new "root" checking node, but they aren't checking for the status of the checkbox before the shift-selection process.
To illustrate: click about ten boxes in a row in the middle of the page. #1 is the top box, #10 is the bottom box. Then, starting at box #7, unclick some boxes in the middle working your way up (say, #6, #5, #4). Then hold down shift and click the box directly above your selection (the equivalent of box #0). Box #4 will also get checked, because that was the last box you selected (and thus, is the current root selection).
posted by Civil_Disobedient at 3:02 AM on May 20, 2006