88 comments

[ 2.1 ms ] story [ 130 ms ] thread
I've been using this for a while. Could have sworn I found it on HN.

Anyway, great utility, extremely useful and could well be the way native drop downs should work.

You may have. I just found it this morning by clicking through a changelog blog post.
Really good stuff!

The only thing I find missing is that, with the keyboard on a multiple select box, I can't remove my 1st choice without having to remove my 2nd choice too. (So, for instance if I choose Polar Bear and also choose Brown Bear, I try to move my cursor between them in order to Backspace over Polar Bear but I can't. I have to Backspace over Brown Bear + Polar Bear in order to delete Polar Bear.) It would be nice if, when I used my direction keys, it would highlight the selected items individually and then let me hit Delete or Backspace on my keyboard to delete just that one.

There appears to be several pull requests related to keyboard controls. I haven't looked into any of them in depth but one of them may solve the issues you are talking about.
Never used the library, but I did inspect the "Multiple Select" control while building something similar last year. So, thanks!
we use this all over the place. awesome lib.
I agree with the consensus that this is a nifty control. That being said, I have had major performance problems when using it with a large set of items in the choice list. Any more than a couple hundred, and it's gonna chug.
We've been using this for what feels like 9 months with Picplum. One thing we did is for on select menus with few items, we hide the search box:

  $(".recipient_relation").chosen disable_search_threshold: 10
And if in Backbone you'd like to have it preselect the value, run something like this after render (so you don't have to add much logic to your handlebar template for the markup):

@$("#address_country_field option").each -> $(@).attr "selected", "selected" if self.model.get("address_country") is $(@).val()

It'd be nice to see some folks share their menu styles. The gradient on the select doesn't quite fit in with all site styles.

FYI, I had to go finding this the other day - it's tricky as mousing out removes the class. Anyway, it's:

    .chzn-container .chzn-results .highlighted
Yeah I remember hunting that as well some time ago
Leaving this here in case it helps someone:

In Firebug, you can ask the :hover state to stay active.

    1. HTML tab
    2. Click on the element
    3. Style menu on the right panel
    4. choose :hover
It tricks the browser into thinking the mouse is really over the element (i.e., it doesn't just add :hover), so if you have a hover class added via JS that should work too.

(Apparently this feature has been there for a long time, but I only found it recently. Changed my Firebug life.)

Thank you very much for showing me this! I can't vote you enough.
(comment deleted)
There is an icon to do the same in the CSS tab of chrome inspector
Is the element you are binding chosen to visible from the start? I'm finding that chosen does not like to be bound to an element until it is visible.

I tend to do a lot of setup on render of fields that are hidden and displayed later in the same view, but chosen throws an error on 'searchfield[0]'.

Correct, it's called after render puts the view into the DOM
Awesome! Might need some work on mobile devices though.
Chosen.js has a great UI, but I found it challenging to do customizations to the library. I wish that the authors of the library had exposed more event hooks or built it with more modularity.

Also worthwhile checking out https://github.com/meltingice/ajax-chosen, which adds much-needed Ajax support to Chosen.js.

Likewise Michael - took a bit of poking around to edit simple UI things.
Yeah it suits Harvest perfectly but as a general purpose library is has some big limitations.
I've used this before but it took a lot of fiddling to get the desired functionality out of it.
Agreed. I tried for a few days before giving up. Unless you're happy with Chosen's default options you'll spend days trying to customize it.
I'm also using this and would like to point out that by default chosen does its instant search using "begins with"-type semantics. To get chosen to do the search using "contains"-type semantics you have to activate a little switch like this: .chosen({search_contains: true}); which isn't immediately obvious from the docs (I had to sift through their issues on github to discover this).
Don't forget about mobile! How this these select boxes work on ios or android?
It works exactly like it does in the browser, meaning, on iOS/Android it doesn't toggle the default OS action for select boxes. A real bummer considering it looks great.
I'll agree with others that it isn't the easiest thing in the world to customize. Here's a hacky approach I threw together under time pressure to reshade it for dark sites, for example:

http://www.exratione.com/2011/12/a-dark-style-for-chosen-sel...

Way too much CSS, but I guess that's par for the course considering how much is going on inside the thing.

It's nice looking and mostly functional but I always miss the native elements.

The thing is, when I see an OS-native-looking element I know immediately what it is.

For the skinned stuff, while it looks nice to the eye, it takes longer. When we're browsing thousand of pages a day it's kind of something you notice.

Nevermind the fact that for certain situations the UX is improved 10 fold over native.
Thanks for sharing it, had not seen it. It looks like Quora's topic selector.
I've been using this a lot in our projects. It would be really a killer for selects with thousands of items. But it really kills the performance at least with Firefox. For small country selects it's still fine.
If you have selects with thousands of items, you really need a better navigation scheme than a select box, even if it does have search.
Really wanted to use this on a recent project, but found the appearance to be too inflexible. Would really like the ability to adjust the height of the element easily.
We use this in our admin section. It's definitely a time saver and a sweet tool, although appearance and behavior customizations are a bit of a pain.
Sorry but this experience is badly broken in iOS and highlights yet again why native controls are always preferable over custom controls for compatibility. Also, don't forget about enabling accessibility by using ARIA.
Similar on Android; the widget behaves perfectly, which is ironically a poor experience on mobile.

Looks like it would be very nice on a desktop though!

Should these sorts of widgets be the default implementation of those types of controls in desktop browsers? As long as they can be done with the same input information, this sort of input seems like a "user preference" issue.
I can't even scroll the list on iPad not sure if everyone experiencing the same.
Yeah, that's why you do it on the client-side. If the widget doesn't work on an iPad then an iPad browser shouldn't default those controls to that widget. A desktop browser could, though Nobody would be worse off, and nobody would be the wiser (except the user).
Multi-select is much less usable unfortunately (no ctrl/shift click, no drag-click).
There is a newer project named Select2 now which handles remote data sets and offers infinite scrolling: http://ivaynberg.github.com/select2/

(Tried to submit it as a story the other day but zero upvotes.)

If I click on one of these and select something then the next time I click it just flickers instead of opening. I think they have something wrong with their event handlers.
Nice! Thanks for sharing - with HN as with anything it's as much chance and timing as anything else as to whether a post gets up-voted or sinks unnoticed. </meta>
Thanks! This is considerably smaller than I expected it to be as well (7KiB minified) which is an acceptable size to chuck into our site.
Where did you get a 7KiB version from? If I download Select2, the select2.min.js file has 22KB
select2-2.0.zip contains a file select2.min.js which is 7KiB gzipped (it's 22KiB uncompressed). I should have stated that was the compressed size.
probably gziped

edit:ops had this in my tab opened since morning and commented without refreshing

I had some trouble viewing data members that were longer than the select box, they would wrap down to a second line and overlap the next entry. I also could not use the mouse to scroll through the list and using the up and down arrows was sluggish. I am dealing with a very large list, but the original chosen seems to handle it pretty well.
This is quite useful for those that feel jittery for having used the same password all over the place: http://leakedin.org/

it allows you to check wether your password is among the leaked ones.

This has nothing to do with the article.