Copy link to clipboard
Copied
Dear All,
I have 4 text fields with number values, where I would like validate the MIN value without zero. Which means that the validation script should ignore zero value(s) and only validate the min value among values, which are (x) > 0. Any idea for a Javascript? Thanks in advance?
Best regards,
Angela.
OK, for future reference, this is called a calculation in the PDF world, not a validation. A validation is when you want to verify that the value of a field follows a specific pattern.
Anyway, you can do it using the following code as the custom calculation script of your minimum-value field (I've also added a command to set the average field value, as you requested):
...var fields = ["Field 1", "Field 2", "Field 3", "Field 4"];
var values = [];
var total = 0;
var n = 0;
for (var i in fields) {
var v
Copy link to clipboard
Copied
In what way is this a validation? Do you just mean that you want to display the lowest (non-zero) number?
And what are the names of the fields?
Copy link to clipboard
Copied
Hello try67,
many thanks for your prompt reply. Yes, the validation filed should show the lowest (non-zero) number.
Field names of validated values: Field 1, Field 2, Field 3, Field 4
In addition I would like to add a second field for validation of the average value of the 4 o.m fields, with exclusion of zero values.
Many thanks for your support.
Copy link to clipboard
Copied
OK, for future reference, this is called a calculation in the PDF world, not a validation. A validation is when you want to verify that the value of a field follows a specific pattern.
Anyway, you can do it using the following code as the custom calculation script of your minimum-value field (I've also added a command to set the average field value, as you requested):
var fields = ["Field 1", "Field 2", "Field 3", "Field 4"];
var values = [];
var total = 0;
var n = 0;
for (var i in fields) {
var v = Number(this.getField(fields).valueAsString);
if (v!=0) {
values.push(v);
total+=v;
n++;
}
}
if (n==0) {
event.value = "";
this.getField("Average").value = "";
} else {
values.sort(function (a,b) {return a - b;});
event.value = values[0];
this.getField("Average").value = total/n;
}
Copy link to clipboard
Copied
Dear try67,
many thanks for your help!