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

Help with validating a numerical (text) field.

Community Beginner ,
Dec 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

On my form I have several numerical fields that must be completed.  I checked the "Required" property box, but I don't see any benefit.  So I used a "On Blur" script type with the javascript below.  This works but the function fires 3 times before the cursor is back in the field for correction.  Below is my script.

var oal = this.getField("OAL");

if (oal.value == 0)

{

app.alert('Must complete Over-All-Length field!');

oal.setFocus();

}

TOPICS
PDF forms

Views

559

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 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

The "required" property is only used when the file is submitted.

What exactly are you trying to achieve? Do you want to prevent the user from entering "0" into this field?

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 Beginner ,
Dec 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

Yes, exactly. I have certain fields that contain measurement data and they can never be 0. So I was trying to validate their entry as they go along.

Tom

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
LEGEND ,
Dec 07, 2017 Dec 07, 2017

Copy link to clipboard

Copied

Use a custom validation script. You'll have to allow a blank value to the field can be reset to blank, so the script could be something like:

// Custom validation script

// The the field value is not blank and evaluates 0...

if (event.value && +event.value === 0) {

    // Disallow the entry

    event.rc = false;

    // Inform the user

    app.alert("Please enter a non-zero value.", 3);

}

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 Beginner ,
Dec 14, 2017 Dec 14, 2017

Copy link to clipboard

Copied

I tried George's code as a validation script, however this code does not stop the Operator from entering by the field without entering anything.  That seems like the most likely Operator error.  Also is there a way to put the cursor back into that field.  So far the cursor moves to the next field after the app alert.

Here is my code:

var oal = this.getField("OAL");

if (event.value && +event.value === 0)

{

event.oal = false;

app.alert('Must complete Over-All-Length field',3);

}

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 14, 2017 Dec 14, 2017

Copy link to clipboard

Copied

try adding this code.

event.target.setFocus();

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Dec 14, 2017 Dec 14, 2017

Copy link to clipboard

Copied

LATEST

I added the line of code suggested by Thom.  It did not put the cursor back into the field to be completed.  Additionally it still does not fire if the Operator simply tabs through the field.  So, I tried a few things and this is where I am at.

1.     I put a default value of 0.00 in the field so that the Operator cannot tab through the field without an error.

2.     I changed the coding from a custom validation script to a Javascript using the On Blur trigger.  This stops the cursor from moving on to the next field, however the app alert fires 3 times before control is returned to the OAL field.  But it does work, if I could make it fire only once.

Here is my current code:

On Blur:  Javascript

var oal = this.getField("OAL");

if (event.value && +event.value === 0)

{

event.oal = false;

app.alert('Must complete the Over-All-Length field!,3);

event.target.setFocus();

}

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