Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cascading dropdown using MySQL tables and ActiveAdmin #918

Closed
A-Random-User opened this Issue · 1 comment

2 participants

@A-Random-User

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
Owner

@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
Something went wrong with that request. Please try again.