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

Question

Question

Repeat collection

asked on November 30, 2015 Show version history

Hi,

I have a form with collection of about 20 fields describing an item (e.g. a vehicle). When the form refers to more than one item (more than one vehicle), the values of the fields will almost be the same but some will need editing. I would want to achieve a situation whereby when I add a new collection the same values are copied into the new collection and all I need to do is edit the ones that are different if not all. My final objective would be to transfer each item into a database as a separate record together with the other data in the form. Thanks in advance

0 0

Replies

replied on December 1, 2015

First I would suggest you name your collections either with a classname or name the variable. The following code assumes you named the variable of the collection. This will only copy the fields if they are the basic field types such as Single-Line, Multi-Line, Radio Button, Checkbox, and Drop-Down. This could easily be expanded for Address, Number, Email, Date, Currency, and Signature field types, I just ran out of time (and interest). You will need to add this script to your "CSS and Javascript" section of your form.

$(document).ready(function() {
function copyFields() {
   var _this=$('li[attr=mycollectionname] div.cf-collection div.form-q:last'), _prev = _this.prev().find('li').each(function() { switch ($(this).attr('attrtype')) {
      case 'text': 
          _this.find('#'+this.id+' input.singleline').val($(this).find('input.singleline').val());
          break;
      case 'radio':
          _this.find('#'+this.id+' input[type=radio][value="'+$(this).find('input[type=radio]:checked').val()+'"]').prop('checked',true);
          break;
      case 'longtext':
          _this.find('[id="'+this.id+'"] textarea').val($(this).find('textarea').val());
          break;
      case 'checkbox':
          var _t = this;
          $(this).find('input[type=checkbox]:checked').each(function(i,e) { 
              _this.find('[id="'+_t.id+'"] input[type=checkbox][value="'+e.value+'"]').prop('checked',true);
          });
          break;
      case 'select':
          _this.find('#'+this.id+' select').val($(this).find('select').val());
          break;
     }
   });
}

$(document).on('click','a.cf-collection-append',copyFields);
});

As for saving the data to a database. Is this an internally developed database? MSSQL, Sqlite, MySql, PostgreSql? Are you wanting to post the values using a webservice? Either way you decide to go, you will need to package the data in a JSON object, serialize it, and send it to a webservice for processing. Let me know if you need more help on this.

1 0
replied on February 8, 2023

Hi is it possible to add a table in a recon form and calculate the total amount e.g the screenshot below:

 

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

Sign in to reply to this post.