Expand my Community achievements bar.

Event fired twice

Avatar

Level 1

Hello,

I would like to pop-up a message when the user closes the form without having clicked on a button.

Therefore I used the event docClose. My problem is that the event is fired twice.

I tried to:

-  put a flag but the variables are reinitialized when the event is called.

- use form variables but even if I modify it in the event the value is set back to the initial value.

- use a field from the form and again even if I modify it in the event the value is set back to the initial value.

I've seen other people having the same issue in other posts but no answer.

Please help.

5 Replies

Avatar

Level 10

Hi,

Sorry, I don't have a direct answer, mainly because I haven't seen this behaviour.

I have a form here: here which looks at events firing. It does use a docClose event, but in our environment it only fires once.

Good luck,

Niall

Avatar

Level 1

Hi Niall,

Thanks for your reply, I had a look at your form and indeed it works. I'm jealous

It seems this issue only occurs when you have interactive forms (Adobe reader rights enabled). In my form if I put a message in the docClose event it's displayed twice.

Avatar

Level 10

Hi,

Okay, I enabled the events form here and...

  • In Acrobat v9 Pro for Mac, the docClose event fires once!
  • In Acrobat v9 Pro Extended for Windows, the docClose event fires once!
  • In Adobe Reader v9 for Windows, the docClose event fires TWICE

When the non-enabled form is opened in Reader, the docClose event fires only once. Note here, that the preSave event does not fire in the non-enabled form:

Parallels Desktop1.png

Searching back through the forum, this post discussed the issue and I had forgotten how many events 'appear' to be firing twice in a form that is Reader Enabled in Acrobat: Extending Reader Rights causing Initialize event to fire twice?

What is interesting is that some of the events fire twice on opening the form and we know that the docClose fires twice on closing (when the form is Reader Enabled).

A clue is the opened state in Acrobat using the non-enabled form and in Reader using the enabled form:

  • In the Reader Enabled form the preSave event fires ONCE (ie there are 13 objects, each with preSave event scripts). But in the non-enabled version the preSave does not fire.
  • Note that in Reader the postSave does not fire on opening the form, even though the preSave does. [EDIT: I suspect that this is because the preSave was not fired by a user action, eg click a button]
  • Note that of the events that do fire on open in the enabled form, only calculate and validate appear to fire once, whereas the rest fire twice.

Parallels Desktop2.png

I suspect that when a Reader Enabled (at least when enabled using Acrobat), the form does a 'save check' which causes some events to fire twice.

I don't think there is a workaround to the docClose event firing twice in a Reader Enabled form opened in Reader, but would be very interested to hear if there is.

Niall

Non-enabled form is available here: http://assurehsc.ie/blog/index.php/2010/05/how-often-events-fire-and-their-sequence/

Message was edited by: Niall O'Donovan

Avatar

Level 1

Hey Neil,

Today I was trying to explain to my colleague why it doesn't work when I found a workaround.

Thanks to your message we know that event a fired a few times and that it open like a copy of the document. I think the copy calls the events and thus displays my message more than once. As I said previously, I tried to work with variables and a if statement to show the message only once but in the copy the variables had the initial value and thus although I changed the flag in the if statement in the main form the message was poping up a second time in the copy.

The solution is simply to change the value of the flag in the docReady event (ie to X) , the flag's value will then be X in the main form when it will be blank in the copies. In the docClose, an if statement can check if the flag's values is X (which is the case only in the main form and not in the copies) and only display the message when it's the case. Thus the message pops up only once. I tried it and it works.

Avatar

Level 10

Hi,

Interesting workaround! Glad you got it working the way you wanted.

Niall