Cocoon data-association-insertion- node with function

According to https://github.com/nathanvda/cocoon#link_to_add_association you have to pass a functiondata-association-insertion-node

I tried this:

<%= link_to_add_association 'Add Timeslot', f, :timeslots, :data => {'association-insertion-node' => 'get_row()'} %>

And this:

<%= link_to_add_association 'Add Timeslot', f, :timeslots, :data => {'association-insertion-node' => 'get_row'} %>

And this (despair):

<%= link_to_add_association 'Add Timeslot', f, :timeslots, :data => {'association-insertion-node' => 'function get_row(node){var row = "<tr></tr>";$("#table_body").append(row);return row;}'} %>

But none of them work.

JavaScript:

function get_row(node){
    var row = "<tr></tr>"
    $("#table_body").append(row);
    return row
}

I am trying to add trin tableand then add the nested form of the slot to tr.

+4
source share
1 answer

At the moment it is not possible what you are trying to do. When installed data-association-insertion-methodlike this, it will be just a string in javascript, not a method reference.

README, ( .add-timeslot):

$(document).on('turbolinks:load', function() {
  $(".add-timeslot a").
    data("association-insertion-method", 'append').
    data("association-insertion-node", function(link){
      return link.closest('.row').next('.row').find('.sub_tasks_form')
    });
});

( - get_row)

+1

Source: https://habr.com/ru/post/1671953/


All Articles