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

Question

Question

Formatting string in a collection

asked on March 29, 2017

I have a collection that allows users to add an account number and supply the dollar amount to be pulled from that account.  I have added the "jquery.mask.min.js" script to the site, and I am able to successfully format the first entry in each collection by referring to the CSS class.  However, when i add a new item to the collection, the formatting does not carry over to the subsequent items in the collection. 

How do I go about remedying this, so that I can format the account number as users enter the information?

Thanks for any help.

0 0

Replies

replied on May 22, 2017 Show version history

I think you are looking for this, similar function to what is used when adding rows to a table but when you have a collection the "Add" action is "Append"

1$(document).ready(function () {
2 $.getScript('http://yourserver/Forms/js/jquery.mask.min.js', function () {
3    $(".ssn input").mask("999-99-9999");
4          $('.cf-collection-append').click(function(){
5           $('.ssn input').mask("999-99-9999");
6          });
7     });
8});

 

1 0
replied on March 30, 2017

Hi Timothy,

Without seeing the existing code, my guess would be that it is applying to all such entries which exist at the time that the particular line executes, and not when new items are added to the collection. You might experiment with the 'DOMNodeInserted' event though there would be some caveats in terms of browser compatibility.

If you're able to provide a minimal sample of code showing how exactly you are implementing the mask, we could try at a more detailed proposition.

Cheers,

0 0
replied on March 30, 2017

OK, I have two collections, each with two components.  I have one section for Revenues and another for Expenses.  In each collection, I have two fields. 

(1) Single line field to gather account number, format 999-999999-999999-99999.  I have added the CSS class: account_number

(2) Currency field to gather the dollar amount to/ from the account, format 999,999,999.  I have added the CSS class: revenue_amount and expense_amount.

I have js code that adds all revenue amounts and expense amounts into a total for each item.  This works, though isn't formatted.  The following js code is what I have:

For formatting:

  $.getScript('https://cocatlfs/Forms/js/jquery.mask.min.js',
    function () {
       $(".phone_number input").mask("999-999-9999");
      $(".account_number input").mask("999-999999-999999-99999");
      $('.revenue_amount input, .expense_amount input').mask('000,000,000,000', {reverse: true});
  });

For totaling each section:

  $('.revenue_block').on('blur', 'input', sumRevTotal);
    function sumRevTotal() {
        var s = 0;
        $('.revenue_amount input').each(function () {
            s += parseRevNumber($(this).val());
        });
        $('.revenue_total input').val(s);
    }
    function parseRevNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    };
  $('.expense_block').on('blur', 'input', sumExpTotal);
    function sumExpTotal() {
        var s = 0;
        $('.expense_amount input').each(function () {
            s += parseExpNumber($(this).val());
        });
        $('.expense_total input').val(s);
    }
    function parseExpNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }; 

The formatting works with the first iteration in the collection, but when a new set of items is added, the formatting does not pick up for either field

I realize that my addition won't work with the commas present in the number, so I will eventually need to clear those to get the math correct, but then I would like to format the total to have the same "000,000,000" format.

I imagine that I am not calling the procedure to do formatting after the second/third/... instance is created. 

(Also, on a side note, the currency fields that do format during entry lose formatting once I exit the field.  Don't know why it isn't staying. )

Thanks for any help.

0 0
replied on March 30, 2017

For the currency fields, I would recommend using the out-of-the-box "use thousands delimiter" option; it'll save you time parsing for JavaScript calculations later.

For the account number fields, I am actually able to use the minimal code:

2  function () {
3    $(".account_number input").mask("999-999999-999999-99999");
4  });

with fields in a collection with the account_number CSS class, and it automatically applies when new items are added. See the attached video for a demonstration. I obtained the minified jQuery mask plugin from this CDN.

Do you perhaps have any additional settings or scripts? Also, what version of Forms are you running? I am on Forms 10.2 Update 1 (10.2.0.834). Lastly, does this behave differently for you in different browsers?

mask.swf (1.27 MB)
1 0
replied on April 4, 2017

I have LF Forms Version 10.1.0.642.  Where do I find the "use thousands delimiter"?  I have not seen this.

0 0
replied on May 3, 2017

Supporting use thousands delimiter for currency field is a new feature in Forms 10.2

0 0
replied on March 30, 2017

I have LF Forms Version 10.1.0.642.  Where do I find the "use thousands delimiter"?  I have not seen this.

0 0
replied on April 6, 2017

So there's no "use thousand's delimiter" for currency?  So... I switch over to a number field to get that option.  I set the decimal places to (2).  Yet, when I type an amount such as "100.01", the results in either the currency field or number field both display "10,001.00".  What's the course of action??? :-/

 

replied on April 6, 2017

And why would there not be a "use thousand's delimiter" available for currency anyway??? 

You are not allowed to follow up in this post.

Sign in to reply to this post.