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

Question

Question

Javascript PO form - calculated item totals not displaying when saved to laserfiche

asked on October 28, 2014

Ok, so I have a customer who used the Purchase Order form example in the forms manual to setup his own customized version of the same. 

 

Everything works and displays correctly when viewing it on the web but when the user finishes the form and Forms saves it as a tiff inside Laserfiche it does not display the calculated item totals on the tif. I am pretty sure there is code out there already to trigger this before it's "printed" to laserfiche but I can't seem to get it right and/or find it.

 

Here's what we have at the moment:

 

$(document).ready(function () {

    $('.cf-table-block').on('blur', 'input', sumtotal);
    $('.tax').on('blur', 'input', sumtotal);
    $('.shipping').on('blur', 'input', sumtotal);
    sumtotal;
});


    function sumtotal() {
        var subtot = 0;
        $('.cf-table-block tbody tr').each(function () {
            var s = 0;
            s = parseNumber($(this).find('.price input').val()) * parseNumber($(this).find('.quantity input').val());
            $(this).find('.subtotal input').val(parseFloat(s).toFixed(2));
            subtot += s;   
         });
                grandTotal(subtot);
    }

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

                function GetUserName() {
        var wshell = new ActiveXObject("WScript.Shell");
        alert(wshell.ExpandEnvironmentStrings("%USERNAME%"));
    }
  
  function grandTotal(s) {
            var sum = 0;
                                sum += s;
            sum += parseNumber($('.tax input').val()) + parseNumber($('.shipping input').val());
        
            $('.total input').val(parseNumber(sum).toFixed(2));
  }

 

0 0

Answer

SELECTED ANSWER
replied on October 28, 2014 Show version history

is the total field read-only? If so, then the value may display in the web browser, but will not be stored and subsequently loaded when saving as TIFF or PDF since it had no value before and it was not supposed to change value.

 

To change this, but have the same functionality, you may want to make that field read-only  via JS Code. You should remove the "read only" option from the field in the "Edit" page, and then follow my instructions below

 

Add the following before your line of code to store the value in the total, modifying the first part to match the field class name you gave to the total.

$('.total input').attr('readonly','False');

Then after the insertion of the value, input the following:

$('.total input').attr('readonly','True');

 

 

Then, add the following at the beginning, this will make the field appear readonly when the page loads. Of course, modify the class name as per the one you need.

$(document).ready(function () {
   $('.total input').attr('readonly','True');
}

 

This recommendation is tested, from my experience, but may require it to be used multiple times if you have readonly fields in multiple locations that are causing you problems. Their will need to be some playing around on your part if using these recommendations for the subtotal field you have

1 0

Replies

replied on October 31, 2014

Hi Chris, 

If your question has been answered, please let us know by clicking the "Mark this reply as the answer" button on the appropriate response.

If you still need assistance with this matter, just update this thread. Thanks!

0 0
replied on November 12, 2014

I finally got the chance to mark this as the answer, as the customer hasn't been available in the last two weeks.

 

Worked well, thanks!

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

Sign in to reply to this post.