Top > Ruby on Railsあれこれ > 複数選択リスト

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
<html>
<head>
  <title>Tutorial: Multiselect index</title>
  <%= stylesheet_link_tag 'ror' %>
</head>
<body>
 
<h2>Tutorial: Multiselect index</h2>
 
<% form_tag :action => 'submit' do %>
select1:<br />
<%= select_tag "select1[]", 
    options_for_select([["One","1"],["Two","2"],["Three","3"]], @selected ),
    {:multiple => true, :size =>3 } %>
<br />
<%= submit_tag "サブミット" %>
<% end %>
</body>
</html>

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
<html>
<head>
  <title>Tutorial: Multiselect submit</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <%= stylesheet_link_tag 'ror' %>
</head>
<body>
 
<h2>Tutorial: Multiselect submit</h2>
 
<% form_tag :action => 'submit2' do %>
select1:<%= session[:select1].join(",") %><br />
select2:<br />
<%= select @select2, "index", @select2List,{}, {:multiple=>true, :size=>3, :name=>'select2[index][]'} %>
<%= submit_tag "サブミット" %>
<% end %>
</body>
</html>

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
<html>
<head>
  <title>Tutorial: Multiselect submit2</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <%= stylesheet_link_tag 'ror' %>
</head>
<body>
 
<h2>Tutorial: Multiselect submit2</h2>
 
select1:<%= session[:select1].join(",") %><br />
select2:<%= @select2.join(",") %><br />
</body>
</html>
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
class MultiselectController < ApplicationController
  
  #初期画面表示
  def index
    @selected = Array.new(["2","3"])
    render :action => 'index.html.erb'
  end
  
  #結果1画面表示
  def submit
    session[:select1] = params[:select1]
    setupSelect2List
    render :action => 'submit.html.erb'
  end
 
  #結果2画面表示
  def submit2
    @select2 = params[:select2][:index]
    render :action => 'submit2.html.erb'
  end
  
  def setupSelect2List
    @select2List = Array.new
    1.upto(3) { |i|
      a = Array.new(["label" + i.to_s, "value" + i.to_s])
      @select2List.push(a)
    }
  end
  private :setupSelect2List
  
end

添付ファイル: filetutorial_msel_3.jpg 377件 [詳細] filetutorial_msel_2.jpg 419件 [詳細] filetutorial_msel_1.jpg 449件 [詳細]

リロード   新規 編集 凍結解除 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2012-08-08 (水) 23:25:47 (2925d)