• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

MIN validation without ZERO

New Here ,
Dec 27, 2018 Dec 27, 2018

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

673

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 27, 2018 Dec 27, 2018

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

...

Votes

Translate

Translate
Community Expert ,
Dec 27, 2018 Dec 27, 2018

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 27, 2018 Dec 27, 2018

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 27, 2018 Dec 27, 2018

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 27, 2018 Dec 27, 2018

Copy link to clipboard

Copied

LATEST

Dear try67,

many thanks for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines