These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Validation wrong focus?

MrTweetyhack
Registered: Aug 29 2011
Posts: 5

Hi, I have a submit button that validates before submitting the data. When I enter data into the field and click on the submit button, it alerts with the message and refocuses on the field. If I press submit again, it checks fine. Why does it not check fine the first time? I added this.getField("Submit").setFocus() to the submit function to see if that'll fix the problem, no go. I read somewhere to use xfa.host.messageBox() but I'm not using xfa and don't really plan to. Any ideas?
 
if(!CheckField("firstname","First name is mandatory")) {return;}
  
function CheckField(name,message){
var f = getField(name);
if(f.value == ""){
app.alert(message);
f.setFocus();
return false;
}
return true;
}

My Product Information:
Acrobat Standard 10.0.2, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
One has to move out of the current field by tab or return.

George Kaiser

MrTweetyhack
Registered: Aug 29 2011
Posts: 5
Thanks but I don't expect users to use tab or return when the button is there for them to click on. Any other solutions? I don't suppose I can use sendkey or setfocus or anything?
mmazal
Registered: Jul 20 2009
Posts: 27
My first guess would be that you cannot use 'name' as a variable since it is a protected word. Otherwise it looks like it should work.
MrTweetyhack
Registered: Aug 29 2011
Posts: 5
Renamed 'name' to 'name0', same behavior.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
(copy of my replies to your post on the Reader forums)

This code does not compile at all. You're calling 'return' outside of a function (in the first line).
How exactly are you using this code? Where is it located?

I would use something like this instead as the Submit button's MouseUp event (of course, you can replace mailDoc with any other method for submitting the file):

  1. if(CheckField("firstname","First name is mandatory")) {mailDoc()}
  2.  
  3. function CheckField(name,message){
  4. var f = getField(name);
  5. if(f.value == ""){
  6. app.alert(message);
  7. f.setFocus();
  8. return false;
  9. }
  10. return true;
  11. }

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

MrTweetyhack
Registered: Aug 29 2011
Posts: 5
Sorry try67, I just didn't put the whole thing in. The submit button calls submit() and it returns if CheckField is fails. It's just the the first click will fail and the second click will succeed. It's as if the data in the field was not committed. Weird. That's why I tried to setFocus() on another field but still no go. Maybe I can do something with the blur event?

function submit(){
if(!CheckField("firstname","First name is mandatory")) {return;}
if(!CheckField("lastname","Last name is mandatory")) {return;}
this.submitForm({cURL: "http://localhost/printvars.php",cSubmitAs: "HTML"});
}function CheckField(name,message){
var f = getField(name);
if(f.value == ""){
app.alert(message);
f.setFocus();
return false;
}
return true;
}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
It works just fine for me.
Even when clicking on the Submit button directly from the text-box after having filled-in a value, it works as expected.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

MrTweetyhack
Registered: Aug 29 2011
Posts: 5
It doesn't seem to work properly for me. Like I said, when I type something in the firstname field and click submit, it highlights the firstname field and says it's empty. Then I click submit again and it passes. Is that what you are getting? What it is supposed to do is say the lastname is empty since I didn't fill that in. I'll try it on another computer, maybe my installation is f'd up.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
If you want, send me the file and I'll have a look at it.
I'm using an earlier version, though, so it might be a version difference.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com