Mandatory Fields

New Here ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

I have three form text fields that need to be completed before the form is submitted (Submit button).

I have checked Required on each text box

I have added the javascript to each of the Required fields (Actions -> Mouse Up - Run a JavaScript)

f=getField(event.target.name)
if(f.value.length==0)
{
f.setFocus()
//Optional Message - Comment out the next line to remove
app.alert("This field is required.Please enter a value.")
}

When I Preview the form and click into the Required field, the alert is displayed but the cursor point doesnt stay in that field.  When I tab the next field is displayed.

I need the alert to display but the cursor to stay in that field so it can be filled.

 

Its probably somethng small that I am missing. Help would be appreciated.

TOPICS
PDF forms

Views

55

Likes

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
Adobe Community Professional ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

No need to set focus because if you click on the field focus is already on the field, just use alert part, but you are using wrong aproach here, you should use script on submit button to check if required fields are empty and then set focus to it, something like this (change field names if needed):

if(this.getField("Field1").value == ""){
app.alert("Field1 is required.Please enter a value.");
this.getField("Field1").setFocus();}
else if(this.getField("Field2").value == ""){
app.alert("Field2 is required.Please enter a value.");
this.getField("Field2").setFocus();}
else if(this.getField("Field3").value == ""){
app.alert("Field3 is required.Please enter a value.");
this.getField("Field3").setFocus();}

Likes

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
Most Valuable Participant ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

If you simply set the fields as Required and add a Submit Form command to your button this type of validation will happen automatically. Of course, then you can't control the message that appears, nor does it check radio-buttons and check-boxes, unfortunately, but that can be done using a script.

Likes

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