Search code examples
validationacrobat

Acrobat XI - Blanking a field if conditions are met


I have a form my drivers complete where part of the form is related to fueling. There is a possibility of 6 separate fuel stops. Each fuel stop line has input where gallons and cost are also included. By default the Cost and Gallons purchased cost is set to $0.00.

My reason for asking assistance: Occasionally the drivers will inadvertently clicks into one of the date fields on a fueling line and the date will auto populate with the then current date (which can be changed). Then the rest of that line remains all zeros.

I am trying to figure out a validation script that will put the date field back to NULL preferably (or blank) if the Fuel Purchase Cost is at $0.00 as well as the DEF Purchase Cost is also $0.00. BOTH of these items need to be true. Additionally I am not sure how to keep the user inputted DATE if FUEL_PURCH_STOP_1 is >0 AND DEF_PURCH_STOP_1 >0.

NOTE: Fueling will always span 2-3 days.

My end goal is... If a driver clicks in the date field inadvertently, the current date is auto populated. Then if there is a "0" in the both the FUEL_PURCH_STOP_1 AND DEF_PURCH_STOP_1 fields then remove the date from that line. If either one or both of the two fields have a value >0 then I want to keep the user inputted date in the field.

I tried:

var v1 = +getField("FUEL_PURCH_STOP_1").value;
var v2 = +getField("DEF_PURCH_STOP_1").value;

// Set this field's value
if v1 >0 andalso v2 >0) {
event.valueAsString === "WHAT GOES HERE??";
} else {
event.valueAsString === "";
}

Solution

  • Put the following script into the custom calculation for your date field.

    var v1 = this.getField("FUEL_PURCH_STOP_1").value;
    var v2 = this.getField("DEF_PURCH_STOP_1").value;
    
    // Set this field's value
    if (v1 == 0 && v2 == 0) {
        event.target.value = "";
    }
    

    Using this script, the date entry will only get modified if both of the other fields are zero. It's left as is when the criteria is not met so you don't actually need the "WHAT GOES HERE??" value.