Skip to main content
Known Participant
May 5, 2022
Question

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

  • May 5, 2022
  • 2 replies
  • 1181 views

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.

This topic has been closed for replies.

2 replies

Legend
May 6, 2022

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!!

Thom Parker
Community Expert
Community Expert
May 6, 2022

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
edm1965Author
Known Participant
May 9, 2022

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). 

Thom Parker
Community Expert
Community Expert
May 12, 2022

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 PDFScriptingUse the Acrobat JavaScript Reference early and often