开发者

Make ajax result as select list with formtastic

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.


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:

:javascript
    new Ajax.Updater({ success: 'some_select_tag' }, '/foo', {
        // process/insert returned html options tags/data however you want
        insertion: 'bottom'
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜