PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

linked list fields

  1. Richard Vav
    Administrator

    I have setup a test form here, http://www.eandhbaxendale.com/testing/ it has two list fields each with 5 columns and I have linked them so if a row is added to one it is also added to the other. This is what I am using to add the rows

    $('#field_22_1 th:last,#field_22_2 th:last').html('<img src="http://www.eandhbaxendale.com/wordpress/wp-content/plugins/gravityforms/images/add.png" class="b-add" title="Add a row" alt="Add a row" style="cursor:pointer;margin:0 3px;">')
    $('.b-add').click(function(){
      $('#field_22_1 .add_list_item:last,#field_22_2 .add_list_item:last').click()
    });

    I would now like do the same with delete row, if a row is deleted from one list field the corresponding row should also be deleted from the other list field, now if I go down the same route as I have done for add row by hiding the original buttons and adding a delete row button to the table header how do I prevent it from deleting the first row when only that remains. The other option would be to leave the existing delete row buttons in place but how do I make them act on both list fields at the same time.

    Posted 11 years ago on Friday February 22, 2013 | Permalink
  2. Richard Vav
    Administrator

    After taking some time away and then a look with fresh eyes I now have the delete row button working in the list field header. I decided that rather than triggering the list fields regular remove row button like I have done with add row I would take a different approach and call the jquery .remove method on the last row as long as it isn't the only row remaining.

    $('.b-delete').click(function(){
    $('#field_22_1,#field_22_2').find('tr:gt(1):last').remove();
      });
    Posted 11 years ago on Sunday February 24, 2013 | Permalink
  3. Very nice. I took a look at the test form and it seems to be working fine.

    Posted 11 years ago on Monday February 25, 2013 | Permalink
  4. Richard Vav
    Administrator

    Thanks Chris, just thinking out loud at this stage for a possible future form.

    Posted 11 years ago on Tuesday February 26, 2013 | Permalink