使用 formattastic 将 ajax 结果作为选择列表
是否可以使用 Ajax 并将结果作为 Formtastic 的选择列表?
示例:
semantic_form_for @user, :url => profile_path(@profile.id) do |f|
- f.inputs do
- f.input :province, :label => "Province", :as => :select, :collection => ["province-1", "province-2", "province-3"]
- f.input :city, :label => "City", :as => :select
- f.buttons do
= f.submit "Submit"
我想让城市的选择列表根据省份动态变化。
is it possible to use Ajax and make the result as select list with Formtastic?
example:
semantic_form_for @user, :url => profile_path(@profile.id) do |f|
- f.inputs do
- f.input :province, :label => "Province", :as => :select, :collection => ["province-1", "province-2", "province-3"]
- f.input :city, :label => "City", :as => :select
- f.buttons do
= f.submit "Submit"
I want to make city's select list change dynamically based on province.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 Protoype,您所描述的内容可以通过几行 Javascript 和 Prototype 来完成 Ajax.Updater。
首先确保传递 Formtastic 参数:include_blank => true 在 f.input 的末尾:collection => [] 行,以便 Formtastic 知道渲染一个空的选择下拉列表。然后让你的控制器返回选项,并在你的 Haml 中:
If you're using Protoype, what you described can be done with a few lines of Javascript and the Prototype Ajax.Updater.
First make sure to pass Formtastic the argument :include_blank => true at the end of the f.input :collection => [] line, so that Formtastic knows to render an empty select drop-down. Then just make your controllers return the options, and in your Haml: