Rails 3.1界面设计——级联下拉、表单输入

发布于 2024-12-10 12:08:12 字数 1158 浏览 0 评论 0原文

对于我有如下模型的情况:

  • Coutries
  • States
  • Cities
  • Opinions

我想首先向用户提供 Coutries 的下拉列表。
选择国家/地区后,国家/地区下拉列表将出现在国家/地区下方。
选择一个州后,城市下拉列表将出现在州下方。
选择城市后,会出现一个文本框,用户可以写下他们对该城市的看法。
将文本放入文本框中后,就会出现“提交”按钮。
一旦用户单击“提交”,我就会处理表单数据。

我想使用之前的选择来填充相应表中的每个下拉列表,以限制下拉项。
我也想要带有复选框的相同功能。

基本上,我希望能够定义级联表单输入方案。我已经看到了有关该主题的一些信息,但没有任何关于 Rails 3 的内容。例如:
Rails 3.1 依赖/级联下拉列表
Rails 3.1相互依赖的选择下拉列表

...似乎只提供部分解决方案。我感觉我可能缺少一些基本的 Rails 概念,并且这个(看似常见的)任务应该更容易。我想简化用户输入体验。我的模型有很多好的默认数据,我想在用户做出输入选择时向他们展示这些数据。我似乎无法在一页上得到所有内容。

当我查找“Rails 动态表单输入”时,我没有得到所需的搜索结果搜索“Rails 级联下拉列表”对一些人有所帮助。 “Rails active form”让我了解了一段互联网历史。

有人可以指路吗?

谢谢!


附录
这似乎暗示了我偶然发现的麻烦:http://guides。 rubyonrails.org/form_helpers.html#building-complex-forms 也许这就是我的答案?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青柠芒果 2024-12-17 12:08:13

我认为 JQuery 是解决这个问题的方法。现在我不是 JQuery 相关问题的专家,但我希望我至少可以为您指出正确的方向。要完成级联列表,您可以根据前一个输入的更改来显示和隐藏选择输入。从那里我会研究一个名为 jquery-chained 的 JQuery 库。该库允许您在州中显示,仅选择属于所选国家/地区的州。我确实有几个链接库的工作示例,如果您愿意,我可以向您展示一个示例,并且我确信有很多在 JQuery 中隐藏和显示表单元素的示例。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文