0

編集:これを探しています: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (これが機能する場合、私は自分の質問に答えます)

formtastic を使用して、in and out タイプの habtm (多くのものがあり、多くに属する) フォームの作成を開始しました。ただし、ユーザーにとってより柔軟にしたいと考えています。つまり、片側で名前を選択すると、すぐに移動するボタンをクリックするか (クリック時に ajax)、フォームが送信された後に移動します。

(私はこれでformtasticを使用していますが、誰かの例ではそうする必要はありません)

私が苦労しているのは、javascript、インとアウトのボタンです..

比較モデル

class Comparison < ActiveRecord::Base
    has_and_belongs_to_many :devices
end

デバイス モデル

class Device < ActiveRecord::Base
    has_and_belongs_to_many :comparisons
end

比較コントローラー

def edit
  @comparison = Comparison.find(params[:id])
  @devices = Device.find(:all, :select => 'id, device_name', :order => 'device_name')

  @devices_selected = @comparison.devices.find(:all, :order => 'device_name', :conditions => ["id IN (?)", @devices])

  @devices_not_selected = Device.find(:all, :order => 'device_name', :conditions => ["id NOT IN (?)", @devices_selected])
end

比較編集ビュー

<% semantic_form_for @comparison do |f| %>
 <% f.inputs do %>
    <%= f.input :comparison_name %>
    <%= f.input :description %>
    <h3>
        Select Devices
    </h3>
    <% f.inputs :class => 'inline_fields' do %>
        <%= f.input :devices,
                    :collection => @devices_not_selected,
                    :label_method => :device_name,
                    :label => 'Add Devices',
                    :input_html => { :size => 20 },
                    :include_blank => false,
                    :hint => 'Select devices from this list to compare to the parent device' %>
        <%= f.input :devices,
                    :collection => @devices_selected,
                    :label_method => :device_name,
                    :label => 'Remove Devices',
                    :input_html => { :size => 20 },
                    :include_blank => false,
                    :hint => 'Deselect devices from this list to take them off the comparison' %>
    <% end %>
 <% end %>
<%= f.buttons %>
<% end %>
4

1 に答える 1

1

この問題を修正するためにjqueryを使用します:

http://quasipartikel.at/2009/05/10/jqueryui-multiselect/

また

http://blog.jeremymartin.name/2008/02/easy-multi-select-transfer-with-jquery.html#

于 2011-02-26T03:30:09.653 に答える