Stefan Cameron on Forms
Building intelligent forms using Adobe LiveCycle Designer

Bug: Cannot Override Calculations

Description

The XFA language supports fields which are calculated yet still overridable by the person filling the form. For instance, you may have an invoice on which you calculate the tax associated with a purchase using a calculated field yet, for customers from other countries, you would like to allow them to override the calculated tax amount and enter the correct amount themselves.

To do this, you would use the Object palette’s Value tab and set the field’s Type property to Calculated – User Can Override. You could even go as far as specifying an Override Message which would appear if the user attempted to override the field’s calculated value.

In theory, when the user attempts to override the field’s calculated value, either the Override Message or, if none was specified, an Acrobat default message appears warning that the field is calculated and gives the user the option to continue with the override or to cancel. If the user proceeds with the override, subsequent calculations use the override value instead of the original calculated value regardless of subsequent changes to other fields which the overridden field’s calculations were dependent on.

Unfortunately, there’s a bug in Acrobat that causes the overridden value to be discarded. It manifests itself in a couple of different ways:

  1. Dynamic PDF: Not only will the value specified by the user (the override) not be retained but the Override Message (if specified) won’t be displayed. The behavior is simply to let the user type-in a value but then throw it away and run the calculation again without any warning.
  2. Static PDF: In this case, the Override Message (if specified) is displayed and the user has the option to discard their change or proceed with the override but the specified value is discarded regardless of what they choose to do and the calculation is run again.

Workaround

You could use two fields and a check box where the first field is simply “Calculated – Read Only” and the second field is the override value and is invisible until the check box is checked.

All calculations which depend on the calculated field in question would need to verify the value of the “override” check box: If it’s unchecked, calculations would use the value from the first field which itself may be calculated. If it’s checked, they would use the value from the second field which contains the override value.

Checking the check box would cause the first (calculated) field to become invisible and the second (override) field to become visible. You could even display an Override Message when the check box gets checked and use the

xfa.host.response("Question", "Title", "Default Value")

statement to give the user the option to cancel the override (the return value is null if the user picked the Cancel button).

Fix

Please refer to the Bug List for updated information on the version(s) affected by this bug as well as if and when it was/will be fixed.


Posted by Stefan Cameron on August 29th, 2006
Filed under Acrobat,Bugs
Both comments and pings are currently closed.

2 Responses to “Bug: Cannot Override Calculations”

  1. Eric Bailey on November 10th, 2006

    Thanks for letting us know that user can override doesn’t work properly. However, I can’t get the workaround to work either. Could you give more details on how to accomplish it with maybe some example JavaScript.

  2. Stefan Cameron on November 11th, 2006

    Eric,

    First, let’s make sure you’ve got the field set correct (for my workaround since that’s what you’re trying to figure-out): You should have two numeric fields with one visible and set as “Calculate – Read Only” (using the Value tab on the Object palette) while the other has a type of “Optional” and is initially invisible. Let’s call the first field “NumReadOnly” and the second one “NumOverride”. Then you have a regular check box (no modifications needed). This covers the fields you need to do the workaround to the bug. I’m also assuming you have other numeric fields along with one that’s a total field which sums the values in all the numeric fields. Let’s call that the “Total” field and make it “Calculated – Read Only” as well since you don’t normally allow a total to be overridden.

    Once this is setup, you just need to add the script.

    The check box would get script in its Click event similar to this (shown here in JavaScript):

    if (this.rawValue == 1)
    {
    // confirm override
    var response = xfa.host.response(“Apply override?”, “”, 1);

    if (response == 1)
    {
    NumReadOnly.presence = “invisible”;
    NumOverride.presence = “visible”;
    }
    else
    this.rawValue = 0; // reset check box value
    }
    else
    {
    // confirm override removal
    var response = xfa.host.response(“Remove override?”, “”, 1);

    if (response == 1)
    {
    NumReadOnly.presence = “visible”;
    NumOverride.presence = “invisible”;
    }
    else
    this.rawValue = 1; // reset check box value
    }

    Finally, the Total field would have something like this in its Calculate script (shown here in JavaScript):

    if (CheckBox1.rawValue == 1)
    NumOverride.rawValue + NumOther.rawValue;
    else
    NumReadOnly.rawValue + NumOther.rawValue;

    In the above script, “NumOther” signifies some other numeric field whose value is included in the sum calculated by the Total field’s Calculate event script.