You are viewing limited content. For full access, please sign in.

Question

Question

Populating New Collection Groups with Existing Data

asked on October 12, 2020

Is it possible to populate a collection with information from a previous entry in that same collection? Here's the form I'm working with:

For context, is this a form used to nominate other employees for an award. It is possible to nominate a group of employees as well, and when this happens, those individuals' Director, Deputy Director, and Supervisor are usually the same for everyone being nominated, but not always.

If someone populates the First Name, Last Name, and Email Address for all 3 of those titles and then adds another collection using the "Recognize another employee" button, is there any way for that new collection to default to the values entered in the previous collection, and so and and so forth for all entries that follow?

 

0 0

Replies

replied on January 12, 2021

Here's a start.

This sample assumes that you have three single-line fields in your collection, with CSS Class Names of field1, field2, and field3.

When a new record is added to the collection, it gets the last record in the collection for each of the 3 fields that had a value, and copies that value to the same field in the new record.

$(document).ready(function () {
  
  $('.testCollection .cf-collection-append').click(function(){
    var field1 = '';
    var field2 = '';
    var field3 = '';
    $('.field1 input').each(function(){
      if($(this).val() != '')
      {
        field1 = $(this).val();
      }
    });
    $('.field2 input').each(function(){
      if($(this).val() != '')
      {
        field2 = $(this).val();
      }
    });
    $('.field3 input').each(function(){
      if($(this).val() != '')
      {
        field3 = $(this).val();
      }
    });
    $('.field1 input').last().val(field1);
    $('.field2 input').last().val(field2);
    $('.field3 input').last().val(field3);
  });
    
});

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.