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

Question

Question

automatically add fields to collection depending on a collection

asked on April 17, 2017

Hello, 

 

I have a collection section in the Default page (Collection 1). I also have another collection section (Collection 2) in another page called Upload.

 

 

Assuming that I added 4 fields like above in Collection 1, how can I make it add the same amount of fields in Collection 2 dynamically? And also remove the add button in Collection 2?

 

 

 

Regards,

 

-Guillaume

 

0 0

Answer

SELECTED ANSWER
replied on April 17, 2017 Show version history

Hi Guillaume,

 

This JavaScript will work to fit your criteria.  However, there are some other items that aren't accounted for in this solution.  If you automate adding collection rows, it would also make sense to automate removing them.  This process(removing rows) would much more difficult to code, as the new rows will not exist on page load.  It would also require identifying which row was deleted from Collection A, and ensuring that the appropriate corresponding row in Collection B is removed.

 

Depending on the use case for this functionality, I would recommend considering ways to capture this data in a table instead.  This would tie the values together better, without requiring a lengthy javascript function.

 

As for the solution, this javascript will fit your criteria, but will need to be updated with the appropriate collection IDs:

 

$(document).ready(function() {
  $('#q6 > a').hide();
  
  function addRow() {
    $('#q6 > a').trigger('click');
    $('#q6 > a').hide();
  }

  $('#q1 > a').on('click', addRow);
});

 

#q1 should be replaced with the ID for collection A, and #q6 should be replaced with the ID for collection B.

 

I hope this helps!

-Eric

0 0

Replies

replied on April 18, 2017

Hello Eric,

I tested it on a simple form and it worked perfectly, thank you.

But I need to be able to delete it. Can you help me out?

 

Best regards,

 

-Guillaume

0 0
replied on April 18, 2017

Unfortunately I'm not equipped to write javascript at the level required to do that.  At least not yet anyway ;)

0 0
replied on April 18, 2017

Okay thank you for the help. Please let me know if you get any updates.

By the way, what does the '> a' means in your code?

 

Regards

-Guillaume

0 0
replied on April 19, 2017

"a" is the "anchor" tag in HTML, and the ">" symbol means the first child.  So the selector says "use the first anchor tag found that is a direct child of the #q1 element".

0 0
replied on April 25, 2017

Eric,

I am trying to do something similar to what Guillaume did. I have a Collection 1 (Entrants) at the top of the form. I also have another collection, Collection 2 (Entrants Signatures) at the bottom of the form. I want to have the users be able to add more rows to the Collection 1 (Entrants) and then automatically have it add the same number of rows below in Collection 2 (Entrants Signatures) for them to sign off on before submitting the form. I tried the JavaScript you posted above and it doesn't seem to be working for adding rows.  Are you able to help me?

Thanks,

Vanessa Huynh

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

Sign in to reply to this post.