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.
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();}
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now