Cascading dropdown using MySQL tables and ActiveAdmin #918

A-Random-User opened this Issue Feb 7, 2013 · 1 comment


None yet
2 participants

I have managed to create a drop-down that is filled from the service model. The service model is managed from a MySQL table. I used this code:

f.input :service, :as => :select #<-- :as not really needed, I know...

I would like to have another select box below the service select that is filled with teams from the team model (teams table in MySQL database) based on what the user selected from the service select.

For example if Service 1 was selected from the service select then the team select would be filled with the teams (Team 1, Team 2) that have the foreign key of service_id = 1 in the teams table in the database. If anyone could help with how to insert the correct associations and Formtastic code to achieve this I would greatly appreciate it.


justinfrench commented Jul 4, 2013

@A-Random-User if you want to change one select on the page based on interactions with another select on the page (without reloading the page), you really have a Javascript problem, more than a Rails or Formtastic problem. There's many ways to handle the JS side of this, and Formtastic will need to provide enhanced markup for the team select so that your JS has something to hook into.

You might consider a custom input TeamSelectInput that subclasses SelectInput (:as => :team_select), then you can hook into various methods there to add-in extra markup on each <option> (like a data attribute or a class for each Service). Closing for now, but happy for you re-open if you need further help with the Formtastic side of this (generating markup that will help you hook up the JS you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment