Skip to main content
October 18, 2017
質問

Validation Script Help

  • October 18, 2017
  • 返信数 4.
  • 2966 ビュー

I'm using the following validation script which compares the input argument against the "IC Ref" value and fills the field red or green depending on whether it is greater or less than the "IC Ref" value. 

The problem is that if you input a IC Ref value and fill in the form fields then go back and change the IC Ref value the fill colors do not refresh based off of the new IC Ref value.

Is there a way to get the validation to update based off of a new IC Ref value being entered?

var v = Number(event.value);

var ic = this.getField("IC Ref").value;

if (v>0 && v<=ic) {event.target.fillColor = color.green;}

else if (v>ic) {event.target.fillColor = color.red;}

else event.target.fillColor = color.white;

このトピックへの返信は締め切られました。

返信数 4

October 27, 2017

I apologize again, but I'm a very low level Javascript user and I'm not sure what you mean when referring to doc-level script or what "call it" means.

I think I need to find a more basic function that just averages 6 values.

try67
Community Expert
Community Expert
October 27, 2017

Just copy the entire code, including the last line I provided, under that field's custom calculation script and it will work.

October 27, 2017

Forgive my javascript inexperience, but I'm not fully understanding how to implement your function. 

I will always have 6 fields filled with none being zero, and none being empty.  They are called fill0, fill1 etc.  Can you provide a little more guidance on how I would modify your function to work in my form?

try67
Community Expert
Community Expert
October 27, 2017

You don't need to modify it at all. Just copy it to a doc-level script, and then call it like this from the custom calculation script of your field:

calcAverage(["fill0", "fill1", "fill2", "fill3", "fill4", "fill5"], false, false);

October 27, 2017

Thanks try67.  This has led to one other little issue for my form. 

One of the fields was averaging the values from 6 other fields and then performing the same validation script on it.  I can't have it perform the simple average function and also have a custom calculation script too so I need to write a simple average function before the validation formula.  All of the examples I'm finding are for much more complex scenarios.

I just need to average 6 cells.  Can you help me withe a quick javascript for this to add to my validation script?

try67
Community Expert
Community Expert
October 27, 2017

I've actually written a function that does exactly that, and it's better than the built-in version because you can tell it to ignore empty fields and/or zero values.

/*

    @params

        aFields : an array of the field names to use for the calcluation

        bIgnoreBlanks : a boolean that tells the function whether or not to ignore blank fields

        bIgnoreZeros : a boolean that tells the function whether or not to ignore zero values

*/

function calcAverage(aFields, bIgnoreBlanks, bIgnoreZeros) {

    var total = 0;

    var n = 0;

    for (var i in fields) {

        var f = this.getField(fields);

        if (f==null) {

            console.println("Error! Can't locate a field called: " + fields);

            continue;

        }

        if (f.valueAsString=="" && ignoreBlanks) continue;

        var v = Number(f.valueAsString);

        if (isNaN(v)) continue;

        if (v==0 && ignoreZeros) continue;

        total+=v;

        n++;

    }

    if (n==0) event.value = "";

    else event.value = total/n;

}

October 27, 2017

Can anybody help with this?  Even if its just to let me know that this isn't possible within an acrobat form?

Thanks

Bernd Alheit
Community Expert
Community Expert
October 27, 2017

Where did you add the script?

October 27, 2017

I'm not sure I understand the question?

The script is part of the field's properties under the "Run custom validation script" section of the "Validate" tab.