Hello,
I have created a form with required fields. The PDF will not be "submitted" with a Submit button. However, we still want it to be fillable and have some required fields. I pulled the JavaScript below from The Adobe Acrobat Developer Tips and it works great on my Mac. However, when I test on the Windows side it freezes and crashes Adober Reader X.
I used Acrobat Pro 9 on my Mac side to create the form. I use the same versions of Acrobat Reader X on the Windows side and Mac side.
Here is the JavaScript I am using.
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.")
}
I removed the JavaScript action and tested again on the Windows side and it opened fine BUT of course the required function is not there without the JavaScript. So, it seems as though the JavaScript is causing a weird compatability issue? I'm just not sure what the solution is.
Any guidance is greatly appreciated. ![]()
Where are you putting your code? Is it in a field event, or document event?
Also,
f = getField(event.target.name)
can be shortened to
f = event.target
and you can shorten it even further if you just need the value from
f = getField(event.target.name)
if (f.value.length == 0)
to one of the following (depending on which event you are using for your code
if (event.value.length == 0)
if (event.target.value.length == 0)
Which action? I'm assuming the 'onBlur' event
Shortening the code won't change how it runs. The event.target is the field itself, so you don't need to get the name to access the field, but either way should produce the same results (unless there was an issue on the PC, but I doubt that)
fwiw, your code works fine on my PC in the OnBlur event of a field.
On the Windows side when I try to open the form here is what happens:
1. I can open the fillable form (PDF).
2. When I click into the first required field (with the JS action) and try to click into another required field without typing anything in the first required field, I do get the correct popup message reminding me about the required information. BUT... then for some reason it will not let me type anything and then I have to hit Control Alt Delete to get out of Reader. The popup message stays on the screen, I can see my cursor within the form field but nothing happens when I type.
I;ll see if I can test it in Reader, perhaps there's an issue there.
Does it work if you comment out the 'setFocus' line?
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.")
}
Or if you comment out the alert line?
One issue that I just ran into.... ![]()
If I click inside a required form field without typing anything and then click inside of another required form field I get the correct popup JavaScript message. BUT.... the cursor does not stay in the first required form field that I clicked out of. It moves to the next required form field. Is there a way to make the cursor stay in the first required form field until you fill it out?
Thanks!!! ![]()
North America
Europe, Middle East and Africa
Asia Pacific