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

Question

Question

Setting Number of Rows for a collection from a variable

asked on November 22, 2017

Is there a way to set the number of rows in a collection from another variable in a form?  For example, if we have a form that has a variable for number of guests, we need the number of rows for Guest Information to match that variable.  Meaning, if the number of guests is set to 2, this should create a collection with 2 rows. 

0 0

Answer

SELECTED ANSWER
replied on November 22, 2017 Show version history

Hi Jen, try this code, where 'theNumber' in this case is the field you want to base the number on, and substitute #q15 for the collection id you are going to use:

 

$('.theNumber input').change(function(){
  var numberCols = $('.theNumber input').val();
  for (var i = 0; i < numberCols; i++){
  $('#q15 .cf-collection-append').trigger('click');
  }
});

Hope this helps,

Rick

0 0
replied on November 22, 2017

Hi Rick, 

Thanks for the suggestion.  It's not quite working for me yet.  How should I have the Collection Options set to use this code?

0 0

Replies

replied on November 22, 2017

0 0
replied on November 22, 2017

I must be missing something.  My collection settings match yours but it's still not working.  What type of field are you using for 'theNumber'?  I've tried using a Number field as well as a Single line but neither is working.

0 0
replied on November 22, 2017

It's just a Single Line Field....make sure the #q number ID is for the Collection Header instead of for the first field in the collection.  It also has to be inside a document ready function.

0 0
replied on November 22, 2017

I got the code sorted out and it's working!! Thank you so much for your help.

0 0
replied on November 16, 2020

I am still pretty new to LaserFiche and Javascript.

I am trying to make sure that my code is correct, since it isn't working...

I am trying to create the collection based off a number (which is a single line field)

$(document).ready(function() {
  $('.Substandard').change(function(){
  var numberCols = $('.Substandard').val();
  for (var i = 0; i < numberCols; i++){
  $('#q109 .cf-collection-append').trigger('click');
  }
});
}

 

0 0
replied on November 19, 2020 Show version history

Bryant, use $('.Substandard input') and try that, instead of $('.Substandard')

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

Sign in to reply to this post.