lundi 18 février 2019

How to show a alert before sending a form in Rails?

Im trying to show a confirmation button before sending a form in ruby on rails.

The problem is that the solution Im using its not working. First, it shows the alert twice, and after pressing the button 2 times, the form is not sent, and nothing happens.

Here is my code

  <%=form_for @transaction, :url => delete_duplicated_items_transactions_path(),:html=>{:class=>"form-horizontal bol-form"} do |f|%>

    <div>
      <script type="text/javascript">
        var checked = false;
        function selectAll(){
          checked = !checked;
          console.log(checked);
          $("input:checkbox").each(function(){
            $(this).attr('checked', checked);
          });
          return false;
        }
      </script>

      <table class="admin-table data-table" id="usertable">
        <thead>
          <tr>
            <th><input type="checkbox" onclick="selectAll()">Select All</a></th>
            <th>Bill of Lading Name</th>
            <th>Product Lot id</th>
          </tr>
        </thead>
        <tbody id="bill_of_ladings_body">
          <% duplicated.each do |element|%>
            <tr id="row_user_<%=element["product_lot"].id%>">
              <td><%= check_box_tag "product_lots[]", "#{element["bill_of_lading"].id.to_s};#{element["product_lot"].id.to_s}" %></td>
              <td><%=link_to element["bill_of_lading"].name,edit_bill_of_lading_path(:id => element["bill_of_lading"].id)%></td>
              <td><%= element["product_lot"].id %></td>
            </tr>
          <%end%>
        </tbody>
      </table>
    </div>
    <div class="admin-table data-table">
      <br>
      <td align="right">
        <%=f.button "Remove from Bill of Ladings", name: "transaction_type",value: 'remove', :class=>"btn btn-info","data-loading-text"=>"Processing..."%>      
        <%=f.button "Remove from Bill of Ladings and Recycle", name: "transaction_type",value: 'remove_and_recycle' , :confirm => 'If you proceed, the system will delete the selected Lot IDs from the selected Bill Of Ladings and will then recyle all Lot IDs added on the previous step. Any Lot ID that is not selected on this list will not be removed from the corresponding Bill of Lading/s and will not be recycled. Are you sure you want to continue?', :class=>"btn btn-danger","data-loading-text"=>"Processing..."%> 
    </div>
    <div class="alert alert-block">
      <h4>Note: Recycle action won't be applied to any item that is not selected above and it will remain linked to the Bill of Lading mentioned on the corresponding row</h4>
    </div>
  <% end %>

What im doing wrong here?

Aucun commentaire:

Enregistrer un commentaire