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

Question

Question

count for collection

asked on September 8, 2016 Show version history

I want to keep of count of the number of Dependents in the Collection.  I have an initial number from the lookup table that is filling the Collection.  How do I keep the count updated when the "Add" or "Delete (X)" controls are clicked?

 

In the JavaScript designer:

 

0 0

Answer

SELECTED ANSWER
replied on September 9, 2016

You just need to add some event listeners in your JavaScript section to handle the math when those buttons are clicked. Something like this should get you close:

$(document).ready(function(){
  $('#q103 .cf-collection').on('click', '.cf-collection-delete', function(){
    $('#q301 input').val((parseNumber($('#q301 input').val())-1).toString());
  });
  $('#q103 .cf-collection-append').on('click',function(){
    $('#q301 input').val((parseNumber($('#q301 input').val())+1).toString());
  });
});

function parseNumber(n) {
  var f = parseFloat(n); //Convert to float number.
  return isNaN(f) ? 0 : f; //treat invalid input as 0;
}

 

0 0
replied on September 9, 2016

Perfect!!

0 0

Replies

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

Sign in to reply to this post.