harvesthq/chosen — pull request #1070 by tjarratt (2013-03-06 03:01:58+00:00)
Title: Fix external js updates to multi-selects

I ran into some issues where updated multi selects from external
javascript (using $(select).trigger("liszt:updated") would frequently
get out of state because the #choices variable on the Chosen object
was no longer the same as the actual number of options selected.

Instead of having a global variable on the chosen jquery object
(which is relatively fragile because of external changes to the
select element), just calculate it as needed. It's not called often
and this is a fairly fast lookup for jquery and prototype, so I think
this is a safe change.

This is my first pull request on a js project using coffeescript, so
any feedback is welcome. I'm already using this patch in a production
setting, so if you'd like I could describe the actual use case that produced
this error condition, or provide a minimal reproduction of the issue but
in my opinion this is a fairly clear change that resolves some of the bugs
one would encounter using chosen with ember.js, or another UI heavy
library where updates to the select element are not always through user
interaction.