javascript - Triggering a click through Jquery on ruby code -


so i'm trying f.submit triggered when click f.check_box. don't know if can use jquery work on ruby... view of to-do list items on page. when click checkbox mark off, want automatically submitted.

i thought assign div tag on f.check_box , f.submit trigger them... first bit of jquery i've working with.

<h1><%= @list.title %></h1>      <script src="//code.jquery.com/jquery-1.10.2.js"></script>     <div>      <h2><% @list.items.each |item| %></h2>     <%= item.content %>       <%= form_for([@list, item]) |f| %>       <div id="target">         <%= f.check_box :complete %>       </div>         <div id="handler">           <%= f.submit %>           <% end %>           </div>     <% end %>      </div>     <script>       jquery(document).ready(function() {          jquery("#target").click(function() {           jquery("#handler").click();       });      });      </script>         <% if policy(@list).update? %>       <%= link_to "edit list", edit_list_path, class: 'btn btn-success' %>       <% end %>         <div class="col-md-4">        <% if policy(item.new).create? %>          <%= link_to "new item", new_list_item_path(@list), class: 'btn btn-success' %>        <% end %>         <% if policy(@list).destroy? %>           <%= link_to "delete list", @list, method: :delete, class: 'btn btn-danger', data: { confirm: 'are sure want destroy lovely list?'} %>           <% end %>      </div>     </div>        <%= render "items/form" %>         <!--      new_list_item_path      /lists/5/items/new      --> 

div not fire onclick event need set onchange method of checkbox submit form.

here code that. need set different id every submit-button , can submit form using jquery.

i set onchange method of checkbox submits forms according item id.

<h1><%= @list.title %></h1>      <script src="//code.jquery.com/jquery-1.10.2.js"></script>     <div> <%index=0%> <h2><% @list.items.each |item| %></h2> <%= item.content %>   <%= form_for([@list, item]) |f| %>     <%=f.check_box :complete,{:onchange=> "submit_form("+@list.items[index].id.to_s+");"}%>       <%= f.submit :id=>@list.items[index].id%>        <%index+=1%>       <% end %> <% end %>  </div>      <% if policy(@list).update? %>   <%= link_to "edit list", edit_list_path, class: 'btn btn-success' %>   <% end %>     <div class="col-md-4">    <% if policy(item.new).create? %>      <%= link_to "new item", new_list_item_path(@list), class: 'btn btn-success' %>    <% end %>     <% if policy(@list).destroy? %>       <%= link_to "delete list", @list, method: :delete, class: 'btn btn-danger', data: { confirm: 'are sure want destroy lovely list?'} %>       <% end %>  </div> </div>    <%= render "items/form" %>    <script>     function submit_form(id) {          $('#'+id).click();     }  </script> 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -