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

Question

Question

Repeat Collection based on a field value

asked on January 19, 2018

Hello,

Is it possible to repeat a collection based on a numeric field value in Forms?

I have a warehouse that is checking in items, with a collection containing serial numbers and asset tags. There can be 1 to 20 units for each item checked in. For example, we may check in 10 Chromebooks in a single shipment, and would need to record the serial number and asset tag for each.

We would like the user to be able to put a number in a field, and have that number of lines appear on the form to populate data into, without needing to click the "add" button after each one.

Thanks!

1 0

Replies

replied on January 19, 2018

You can do this with javascript. Have javascript read the number entered in the field and then click the Add link however many times necessary. Here's the basic script to do that:

function AddCollections() {
  	var count = $('.num input').val();
  
  	for (i = 0; i < count-1; i++) { 
    	$('.my-collection a.cf-collection-append').click();
	}
}

$(document).ready(function() {
     $('.num input').change(AddCollections);
});

where .num is the number field and .my-collection is the collection to be duplicated. You may want to add code to account for changes to the number.

1 0
replied on January 22, 2018

Thanks, Sheila.

 

That worked.  smiley

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

Sign in to reply to this post.