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

Prevent advancing to next (or another field) until valid/proper entry of current field

Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

So I have a form with REQUIRED fields that cannot be left blank. Two fields in particular are important. What I'd like to have hapen is that if either of those fields is clicked/tapped/touched (and once they are active), it forces the user to input a valid entry before allowing them to move to the next or to another field. However, once a valid input is entered, they'll be free to advance to the next or another field.

 

Any suggestions?   

 

By default the field is blank. The filed cannot be left blank either. So basically once the user enters that field, they need to complete it before moving on.

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

421

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 ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

A validation script can be used to keep the field focus on the field until a valid value is entered. 

 

Something like this

event.rc = ... Valid Value Test ...
if(!event.rc)
{
     app.alert("You can enter but you can never leave").
     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 ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

Yes, I've gotten that far, however, the user can still skip or advance to another field. I was wondering is there was a way to keep the user locked into that field *until* a valid entry is provided. In other words, once the user selects the field they cannot click or tap on any other field until the field is correctly filled.  The focus works great at zeroing out the field and returning the cursor to the beginning, but the user can simply bypass that field and move onto the next (which happens to also require a valid input before advancing). 

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 ,
May 12, 2022 May 12, 2022

Copy link to clipboard

Copied

LATEST

It's not really a good idea to completely lock the user into a field. But there is a way to do it. 

The Validate event is called when the field value changes. But the OnBlur event is called when the focus leaves the field. Use this a a second level detection to test for an empty field, since the validate is clearing the field. 

 

 

if(event.target.value == "")
{
     app.alert("You're not going anywhere").
     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
LEGEND ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

Be careful not to get in a situation where a valid value is (say) 20 characters to type and the user gets an error for each of the 19 characters they type first! I've done that!!

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