form_for复选框仅适用于第一个jquery-tab

时间:2014-06-18 16:04:57

标签: ruby-on-rails forms loops checkbox jquery-tabs

我正在创建一个form_for,它基本上允许用户在完成视频时进行标记。我将这个表单嵌套在jQuery选项卡中,并且希望每个选项卡上都有一个复选框,到目前为止我已经知道了。但是,功能是失败的功能:只有第一个选项卡上的复选框实际上会在提交时更改值。关于如何解决这个问题的任何想法?

<% for i in 1..@statement %>
<div id="htab-current-<%= i %>">
  <%= form_for @user.workouts.where(week_num:  @week).where(video_num_in_week: i).first.assignedworkouts.first, remote:true ,:html=>{:id=>'completed_form'} do |f| %>
    <%= f.check_box :completed, :onclick => "$('#completed_form').submit()" %>      
  <% end %>

  <div class='videowrapper2'>
    <div id="myElement<%= i %>">Loading the player ...</div>
    <script type="text/javascript">
      jwplayer("myElement<%= i %>").setup({
        skin: 'five',
        width: "100%",
        aspectratio: "4:3",
        listbar: {
          position: 'bottom',               
        },
        playlist: '<%=asset_path(@user.workouts.where(week_num:  @week).where(video_num_in_week: i).first.playlist_file ) %>'
      });
    </script>
  </div>
</div>
   编辑:我尝试过强制它,实际上这是一个表格上的id相同的问题。但是,当我将其更改为动态生成时,即使表单上的ID和jQuery调用相同,它们似乎也无法正常工作。

<% for i in 1..@statement %>
<div id="htab-current-<%= i %>">
  <%= form_for @user.workouts.where(week_num:  @week).where(video_num_in_week: i).first.assignedworkouts.first, remote:true ,:html=>{:id=>"#{i}completed_form'"} do |f| %>
    <%= f.check_box :completed, :onclick => "$('#{i}completed_form').submit()" %>

    <% end %>
  <div class='videowrapper2'>
    <div id="myElement<%= i %>">Loading the player ...</div>
    <script type="text/javascript">
      jwplayer("myElement<%= i %>").setup({
        skin: 'five',
        width: "100%",
        aspectratio: "4:3",
        listbar: {
          position: 'bottom',               
        },
        playlist: '<%=asset_path(@user.workouts.where(week_num:  @week).where(video_num_in_week: i).first.playlist_file ) %>'
      });
    </script>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

尝试:

<% for i in 1..@statement %>
<div id="htab-current-<%= i %>">
  <%= form_for @user.workouts.where(week_num:  @week).where(video_num_in_week: i).first.assignedworkouts.first, remote:true ,:html=>{:id=>'completed_form'} do |f| %>
    <%= f.check_box :completed, :onclick => "$('#completed_form').submit()" %>

  <div class="videowrapper2">
    <div id="myElement<%= i %>">Loading the player ...</div>
    <script type="text/javascript">
      jwplayer("myElement<%= i %>").setup({
        skin: 'five',
        width: "100%",
        aspectratio: "4:3",
        listbar: {
          position: 'bottom',               
        },
        playlist: '<%=asset_path(@user.workouts.where(week_num:  @week).where(video_num_in_week: i).first.playlist_file ) %>'
      });
    </script>
  </div>
</div>

<% end %>