2
votes

For a case where I have models like:

  • Coutries
  • States
  • Cities
  • Opinions

I'd like to begin with just presenting a user with a dropdown for Coutries.
Once a country is selected, then a States dropdown would appear below Countries.
Once a State is selected, then a Cities dropdown would appear below States.
Once a City is selected, a textboxt appears and the user writes their opinion of the city.
Once text is placed in the textbox, a 'submit' button appears.
Once the user clicks 'submit' I process the form data.

I'd like to populate each dropdown from a corresponding table using the previous selection to limit the dropdown items.
I'd like the same sort of functionality with checkboxes too.

Basically, I'd like to be able to define a cascading form input scheme. I have seen some information on the topic, but nothing that wraps it up tight for Rails 3. For instance:
Rails 3.1 Dependent / Cascading Dropdowns and
Rails 3.1 interdependent select dropdown lists

... seem to offer only partial solutions. I am getting the feeling that I might be missing some fundamental Rails concept and that this (seemingly common) task should be easier. I want to streamline the user input experience. My models have a lot of good default data that I'd like to present to the user as they make their input choices. I just can't seem to get it all on one page.

I don't get the search results I am seeking when I look for "Rails dynamic form input" Searching for "Rails Cascading dropdown" has helped some. "Rails active form" gets me a piece of internet history.

Can someone guide the way?

Thanks!


ADDENDUM
This seems to allude to the trouble I have stumbled upon: http://guides.rubyonrails.org/form_helpers.html#building-complex-forms Perhaps that's my answer?

1
and I have found a pretty good 2007 example here: railsforum.com/viewtopic.php?id=2549 - Perry Horwich

1 Answers

0
votes

JQuery is the way to go here I think. Now I am no expert in matters pertaining to JQuery, but I hope I can at least point you in the right direction. To accomplish your cascading list, you could show and hide the select inputs based on the change of the previous one. From there I would look into a JQuery library called jquery-chained. This library would allow you to show in the states select only those states which pertain to the selected country. I do have a couple working examples of the chained library that I could show an example of if you would like, and I am sure there are many examples out there of hiding and showing form elements in JQuery.