• Resolved mikaelrav

    (@mikaelrav)


    I’m just starting out but I think I’ve found a bug.
    I’m using nested loops. Repeatable Rows which then contains repeatable Tiles.

    When I try to add a new row by using the +button a tile is created but in the hierarchy of my rows.

    A visual demonstration
    –Row (When I click the +button here …)
    –Tile
    –Tile
    –Tile (… a Tile is created here. It should be a Row.)

    So basically I try to add a loop element but instead a sub-loop is inserted in its place.

    It might have something to do with this code, but I’m not much of a coder myself.

    Any suggestions?

    $(document).on('click', '.cfs_insert_field', function(event) {
    
    event.stopPropagation();
    
    var $add_field = $('.cfs_add_field');
    
    var num_rows = $add_field.attr('data-rows');
    
    var loop_tag = $add_field.attr('data-loop-tag');
    
    var loop_id = loop_tag.match(/.*\[(.*?)\]/)[1];
    
    var html = CFS.loop_buffer[loop_id].replace(/\[clone\]/g, loop_tag + '[' + num_rows + ']');
    
    $add_field.attr('data-rows', parseInt(num_rows)+1);
    
    $(html).insertAfter( $(this).closest('.loop_wrapper') ).addClass('loop_wrapper_new');
    
    $add_field.trigger('cfs/ready');
    
    });
    • This topic was modified 8 months, 3 weeks ago by mikaelrav.
Viewing 1 replies (of 1 total)
  • Thread Starter mikaelrav

    (@mikaelrav)

    I found a solution. I had to change a line in the code to be more specific.

    var $add_field = $('.cfs_add_field');

    Had to be replaced with:

    var $add_field = $(this).parent().parent().siblings('.table_footer').find('.cfs_add_field');

    I think it will then find the correct add field-button in the DOM.

    • This reply was modified 8 months, 2 weeks ago by mikaelrav.
Viewing 1 replies (of 1 total)
  • The topic ‘Bug? Nested loops, Insert field-button’ is closed to new replies.