Fix broken Chosen dropdowns by replacing chosen-rails gem#2468
Merged
olleolleolle merged 1 commit intocodebar:masterfrom Feb 9, 2026
Merged
Fix broken Chosen dropdowns by replacing chosen-rails gem#2468olleolleolle merged 1 commit intocodebar:masterfrom
olleolleolle merged 1 commit intocodebar:masterfrom
Conversation
## Problem The chosen-rails gem's support-rails-8 branch has broken CoffeeScript compilation that causes Chosen dropdowns to appear empty despite having populated <option> elements in the DOM. The CoffeeScript comprehension syntax was compiling to broken JavaScript with uninitialized loop variables (`for (undefined; i < len; i++)`), causing loops to never execute. This affected both option parsing and DOM rendering. ## Root Cause CoffeeScript 1.12.2 (from 2016) combined with the support-rails-8 branch produces incorrect JavaScript compilation for comprehension loops. ## Solution Removed the chosen-rails gem dependency and replaced it with official pre-compiled Chosen v1.8.7 assets in vendor/: - vendor/assets/javascripts/chosen.jquery.js - vendor/assets/stylesheets/chosen.css - vendor/assets/images/chosen-sprite.png - vendor/assets/images/chosen-sprite@2x.png Updated application.js to require chosen.jquery from vendor instead of the gem. ## Benefits 1. Avoids CoffeeScript compilation issues entirely 2. Removes unnecessary gem dependency 3. Full control over Chosen version 4. Simpler asset pipeline (no gem-based asset resolution) ## Additional Fixes - Fixed JavaScript syntax error in application.js (chosen() options) - Fixed script loading order (jQuery before Bootstrap) - Added blank prompt option to members dropdown ## Testing Verified working: - Member directory dropdown (240 members) - Search/filter functionality - Keyboard navigation - Single deselect option ## Future Consideration This uses the jQuery-dependent Chosen library. Long-term, consider replacing with a modern JavaScript alternative without jQuery dependency.
Collaborator
Author
|
@olleolleolle, once this has merged and deployed, you can safely remove the |
olleolleolle
approved these changes
Feb 9, 2026
Collaborator
olleolleolle
left a comment
There was a problem hiding this comment.
Thanks for all the good context in the PR, and for the fix!
Collaborator
|
https://github.com/olleolleolle/chosen-rails/settings this is the fork I can remove when all is deployed and in prod. |
Collaborator
Author
@olleolleolle it's been deployed to production and is running fine :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During some research on how we might get rid of
chosen, I noticed that we had broken the/admin/memberspage ... which someone had also mentioned on Slack not so long ago.The members directory appears empty
Problem
Admin pages with Chosen dropdowns (members directory, sponsors, invitation management) were broken - dropdowns appeared empty despite having data.
The root cause: the
chosen-railsgem'ssupport-rails-8branch has broken CoffeeScript compilation. CoffeeScript comprehension loops compile to invalid JavaScript:The loop variable
iis never initialized, so loops never execute. This broke:Solution
Replaced the broken gem with official pre-compiled Chosen v1.8.7 assets:
chosen-railsgem dependencyvendor/assets/Benefits
Testing
Verified on member directory page (
/admin/members):Additional Fixes
application.js(Chosen options)Fixes: Empty Chosen dropdowns on admin pages
Type: Bug fix