Как показать предупреждение перед отправкой формы в Rails? - PullRequest
0 голосов
/ 18 февраля 2019

Я пытаюсь показать кнопку подтверждения перед отправкой формы в ruby ​​на рельсах.

Проблема в том, что решение, которое я использую, не работает.Сначала показывается предупреждение дважды, а после нажатия кнопки 2 раза форма не отправляется, и ничего не происходит.

Вот мой код

  <%=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', data:{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" %> 

    </div>

  <% end %>

Что я здесь не так делаю?

1 Ответ

0 голосов
/ 18 февраля 2019

Прежде всего, вы говорите о предупреждениях и подтверждениях, которые являются двумя разными вещами.И у вас также есть div с классом Alert, если быть более точным.

Во-вторых, правильный синтаксис опции raj для подтверждения "ujs" - data: {confirm: 'somestring'}}, вам не хватает ключа "data:".

https://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#confirmations

Кроме того, по этой ссылке, прямо под разделом «Подтверждения», у вас есть раздел «Автоматическое отключение», поскольку вы используете data-loading-text, а рельсы уже могут справиться с этим с помощью data-disable-with

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...