Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Alert message error - need help

Avatar

Level 1

I'm very poor in the javascript department when developping PDFs and I would need a little help with this issue.

On one row, I would need field C to check on exit if Field A is larger than field C. If field A is not larger, then I need an alert message to pop up and say "Field C cannot be larger than field A." and then the cursor would return to field C, and the value of field C would become 0 (zero).

I've tried a few ways, but I do not seem to be getting it right. Any one have a clue how to do this effectively?

Thank you!

12 Replies

Avatar

Level 10

I think something like this should work on the exit event of FieldC:

if (this.rawValue > FieldA.rawValue)
     {
          xfa.host.setFocus(FieldC);
          FieldC.rawValue = 0;       
          app.alert("Error Message Here");
     }

Avatar

Level 1

This got the message to pop up, but the cursor didn't go back into the field as it should have.

Avatar

Level 10

Hmm...not sure what's up with that. I tried rearranging the order of operations but that didn't help either.

It's odd because it does highlight the "0" and if you press Enter when entering the number it does work but tabbing out of the field doesn't.

I tried it with FieldC.rawValue = null; as well, and then you just get the cursor blinking in the field but still can't type if tabbing out initially.

Hopefully someone here can shed some light on this.

Avatar

Level 2

Change the script below:

if (this.rawValue > FieldA.rawValue)

{

FieldC.rawValue = 0;

app.alert("Error Message Here");

  • xfa.host.setFocus(FieldC);*

}

Avatar

Level 10

More on that:

It only seems to happen if you tab into the field and tab out, if you click into the field and then tab out it works.

Also, it only behaves badly the first time through...if you go back to FieldA and then tab to FieldC again and tab out it works.

Avatar

Level 7

This will work for you. The problem is that the message box takes the focus when it pops up. This script in my sample requires the user to clear the message and sets the focus back to FieldC based on the users button click. You'll need to change the path on my script to match your own hierarchy, I've used form1.subform1.FieldC.

Avatar

Level 1

This didn't seem to work on my file either, but I am content with what I've got. Thank you very much!

Avatar

Level 7

The sample I posted didn't work? That's strange, it worked fine when I tested it. Did you change the path to fit your form?

Avatar

Level 10

Still does the same thing for me too. And operates the same as the notes I mentioned above.

I guess there's no way to get focus fully back after a popup?

Avatar

Level 7

It would appear that there isn't. The sample I posted worked for me, which makes me think there are other factors involved such as:

1. What version of compatibility are you saving the form as? (I saved it as compatible with 8.1 or later)

2. What program is being used to open the pdf? (I used Acrobat 8.1.6)

3. Is the user actually clicking the button with the mouse or simply hitting the Enter key to answer the pop-up? (I clicked it)

4. Machine OS (I'm using 64-bit XP, Service Pack 2)

Something else is going on that is making the pdf perform differently, maybe something as simple as the form moving outside the environment it was created in. No matter what the reason is, controlling the focus is the issue and it doesn't look to be something we can control reliably.

Avatar

Level 1

try this

if (this.rawValue > FieldA.rawValue)
{
     this.rawValue = "";
     if (xfa.host.messageBox("error message here","warning here",0,0) == 1)
     {
         xfa.host.setFocus(FieldC);
     }
}