0

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"

都市の選択リストを州に基づいて動的に変更したいと思います。

4

1 に答える 1

1

Protoypeを使用している場合は、数行のJavascriptとPrototypeAjax.Updaterを使用して説明したことを実行できます

まず、Formtasticに引数:include_blank => trueをf.input:collection => []行の最後に渡して、Formtasticが空の選択ドロップダウンをレンダリングすることを認識できるようにします。次に、コントローラーにオプションを返してもらい、Hamlで次のようにします。

:javascript
    new Ajax.Updater({ success: 'some_select_tag' }, '/foo', {
        // process/insert returned html options tags/data however you want
        insertion: 'bottom'
    });
于 2009-12-17T06:17:20.390 に答える