1

I have 2 tables: Products and Services. I have added products and services to cart functions as rows.

So on each click on trash image, I need to pass as an product and service ids as an array.

<% @service_appointment_operation.each do |sao| %>
          <tr  style="color: #e06d6d;" data-tt-parent-id="ser_<%= @service_appointment.id %>" data-tt-id="ser_<%= @service_appointment.id %>_<%= sao.operation.id %>">
            <td><span class="glyphicon glyphicon-trash" onclick="deleteRow(<%=service_appointment.id%>,'<%= sao.operation_type %>')"></span></td>
          </tr>
          <% end %>

JavaScript function:

function deleteRow(id,type) {
  var operation_type = type;
  if (operation_type == "Service") {
    $('#deleted_service_ids').val(id);
  } else {
    $('#deleted_product_ids').val(id);
  }
}

Form Hidden fields

<%= hidden_field_tag "deleted_product_ids[]", "", id: "deleted_product_ids" %>
<%= hidden_field_tag "deleted_service_ids[]", "", id: "deleted_service_ids" %>

Now I am getting params as one product id, one service id. How can I pass ids as an array if I delete more than one product and service? How can I pass values of products and services as an array to hidden field?

4
  • I can't get what u mean. You want to have a button massively delete rows and pass all those rolls' data for sth else? Commented May 18, 2018 at 7:31
  • @ MatrixTai i want to pass product and service ids as an array on click, now onclick it is passing only one product and service id. Commented May 18, 2018 at 7:40
  • see now it is passing like this 'Parameters: {"utf8"=>"✓", "authenticity_token"=>"Uvuezyw1izPomzf5LSfgbov7AjB5Q0kofmto7AZ9xlVco1C7HQ7LYNxJxSyNUP0sBd4gtGEmDI1aAgOZBqKkBg==", "deleted_product_ids"=>"2", "deleted_service_ids"=>"2", "commit"=>"Next", "id"=>"2"}' Commented May 18, 2018 at 7:44
  • But i want to pass params like this, deleted_product_ids"=>"1,3", deleted_service_ids"=>"2,4" Commented May 18, 2018 at 7:45

1 Answer 1

1

If I get what you mean correctly,

function deleteRow(id,type) {
  var operation_type = type;

  if (operation_type == "Service") {
    var org_value = $('#deleted_service_ids').val()
    var sav = org_value ? org_value  + ',' + id : id;
    $('#deleted_service_ids').val(sav);
  } else {
    var org_value = $('#deleted_product_ids').val()
    var sav = org_value ? org_value  + ',' + id : id;
    $('#deleted_product_ids').val(sav);
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.