Expand my Community achievements bar.

SOLVED

Add pop up information after button/script is executed.

Avatar

Level 2

Can you add a pop up with information after a button is executed?  I'm new to LiveCycle and have, with help from this forum, created a button that locks fillable form fields upon execution.  What I'm wondering is if a pop up can be added after button execution advising the user to save the form with a different file name (to retain base form for future use) before finalizing the document.

For example, we've created a quotation form to send out to our field to use when preparing quotes for customers.  Before they email the quote to the customer, I've added the button to lock the fields first.  However, if I got this right, and they save the form, without doing a save as another file name, they will eliminate the ability to use the base form again.

I was also wondering if the button could be eliminated during the save as another file name process (so the end recipient doesn't see the button at all).

Hope I've explained this clearly enough.

Any other thoughts on how other form creators have accomplished similar tasks would be appreciated too.

Thanks!!!!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

A button has three events that are associated with a user clicking the button:
      mouseDown
      mouseUp
      click

It is generally not a good idea to put script that changes the form or data in the mouseDown event because it does something before the user has fully committed to the click action. In other words the user could click down on the button and then change their mind and move the mouse off the button before they release the click.

This leaves two events. IF all of your script works as one block, then you should place it in the click event. But if it doesn't and you need separate events, then you can put the first portion (action) in the mouseUp event and the last part in the click event.

On the basis that it will all work in the click event you could have the following two lines after the lock all fields:

this.presence = "invisible"; // hides the lock button
xfa.host.messageBox("The form is now locked, please remember to make sure you save it with a different name", "Customer quotes", 3, 0);

This gets a status message to the user, confirming that the form is locked. If you get this working then it will get you out of the blocks.

It is a bit better to make sure that the user saves as new name before you lock the form. You could do this two ways. One would be to test the file name string against the template name. If there are different it means the user has renamed the form. However this can be troublesome to maintain, because if you rename the template you must remember to go in an amend the script.

Another way would be to wrap the whole script block up into another messageBox statement that would look at what the user clicks (Yes or No).

It would look like this:

var nChoice = xfa.host.messageBox("You are about to lock the form.\n\nIf you have not renamed the file, you will not be able to lock the form. Please click No and rename the form first.\n\nHave you renamed this file?", "Customer quotes", 1, 2);

if (nChoice == 4)
{
... All your script...

this.presence = "invisible"; // hides the lock button
xfa.host.messageBox("The form is now locked, please remember to make sure you save it with a different name", "Customer quotes", 3, 0);
} //close if statement.


I hope that helps,

Niall

View solution in original post

17 Replies

Avatar

Correct answer by
Level 10

Hi,

A button has three events that are associated with a user clicking the button:
      mouseDown
      mouseUp
      click

It is generally not a good idea to put script that changes the form or data in the mouseDown event because it does something before the user has fully committed to the click action. In other words the user could click down on the button and then change their mind and move the mouse off the button before they release the click.

This leaves two events. IF all of your script works as one block, then you should place it in the click event. But if it doesn't and you need separate events, then you can put the first portion (action) in the mouseUp event and the last part in the click event.

On the basis that it will all work in the click event you could have the following two lines after the lock all fields:

this.presence = "invisible"; // hides the lock button
xfa.host.messageBox("The form is now locked, please remember to make sure you save it with a different name", "Customer quotes", 3, 0);

This gets a status message to the user, confirming that the form is locked. If you get this working then it will get you out of the blocks.

It is a bit better to make sure that the user saves as new name before you lock the form. You could do this two ways. One would be to test the file name string against the template name. If there are different it means the user has renamed the form. However this can be troublesome to maintain, because if you rename the template you must remember to go in an amend the script.

Another way would be to wrap the whole script block up into another messageBox statement that would look at what the user clicks (Yes or No).

It would look like this:

var nChoice = xfa.host.messageBox("You are about to lock the form.\n\nIf you have not renamed the file, you will not be able to lock the form. Please click No and rename the form first.\n\nHave you renamed this file?", "Customer quotes", 1, 2);

if (nChoice == 4)
{
... All your script...

this.presence = "invisible"; // hides the lock button
xfa.host.messageBox("The form is now locked, please remember to make sure you save it with a different name", "Customer quotes", 3, 0);
} //close if statement.


I hope that helps,

Niall

Avatar

Level 2

Thank you!  That's the information and help I was looking for.  And, thanks so much for the sample.  I'm extremely new to LiveCycle (as in just a couple of days!) so the sample was a life saver so I could actually see the script in place and working.

Question on the sample, the message advises I won't be able to save the form after locking.....but it actually did let me save the form without renaming?  I do wholeheartedly agree with your statement though regarding having to the script test the file name string or having to modify the script on future forms (ugh, not a good idea for me right now).  I think just having the informational message "should" be enough.....but you know some users......   If I did want to add this feature?

Another question......If I save your button to my favorites, I should be able to just drop it into any form I'm creating right (again, newbie and sorry)?

Again, thank you, you've been incredibly helpful.  : )

Avatar

Level 10

Hi,

No problem - there are lots of examples on the forum, on the Adobe website and on Acrobat Users.

The text in the messageBoxes are up to you. You can tweak them to suit. You are right, the lock scripts does not prevent the form from being saved. Again you can amend the text to suite your users. One aspect to look at is that when you are building up your message you can use \n to create a line break. This spaces out your message into manageable blocks.

If you wanted to test the current file name against the template name ("customer quote form 01.pdf"), then it would look "something" like this:

var vCurrentName = event.target.documentFileName.toString();

if (vCurrentName != "customer quote form 01.pdf")

{

// do the lock all fields script...

}

else

{

     xfa.host.messageBox("Tut, tut, tut - you haven't save the form with a new name yet. Please do it now", "Customer quotes", 3, 0);

}

If you look in the Object Library, there are different groups. You can create your own group (via the little pull out menu to the right). You can drag the button off the sample form and into the Object Library. Then in any new form you can drag this custom button onto the design view. You may need to change some of the variables/script to suit.

Good luck,

Niall

Avatar

Level 2

Thank you, again!  Your expertise is sincerely appreciated.

Avatar

Level 2

Hello again.  I've tried executed the button script on a newly created form.  I've tried adding my own button and then adding the

script, and separately, just copying your button into the form.  Can't seem to make it work.

This is an absolutely awesome script and really want to put it to use.  Was wondering if you could help me figure out what's wrong with mine?  Would it be okay to send my document to you to review?  Not sure how to do that on the forum as you did with your example.  I'm not seeing an upload or attachment button here.

Let me know.  And, again, thanks for your time on this.

Avatar

Level 2

Posted to forum, but am replying with duplicate post here as well as the attachment if in case you would take the time to look at it.

Hello again. I've tried executed the button script on a newly created form. I've tried adding my own button and then adding the

script, and separately, just copying your button into the form. Can't seem to make it work.

This is an absolutely awesome script and really want to put it to use. Was wondering if you could help me figure out what's wrong with mine? Would it be okay to send my document to you to review? Not sure how to do that on the forum as you did with your example. I'm not seeing an upload button here.

Let me know. And, again, thanks for your time on this.

Avatar

Level 10

Hi,

If you upload the form to a collaboration website like Acrobat.com or yousendit.com and then send me the link. I will try and have a look. I am closing down for the evening, but will have a look tomorrow.

Niall

Avatar

Level 10

Hi,

I am working on it...

You have kept the reference to Textfield1 and Textfield2 in the script and these objects do not exist on your form.

I will post something later/tomorrow.

Niall

Avatar

Level 10

OK,

I have uploaded a sample here: https://acrobat.com/#d=bph8py51lq8sJMaWRNNnjA

It uses Paul Guerette's sample for "LockAllFields".

Your form highlighted an interesting issue that setting access to readOnly is not passed through groups. So I have taken your groups out and replaced them with subforms.

The following now works (which calls Paul's script object - in the hierarchy/variables).

var nChoice = xfa.host.messageBox("You are about to lock the form.\n\nIf you have not renamed the file, you will not be able to lock the form. Please click No and rename the form first.\n\nHave you renamed this file?", "Customer quotes", 1, 2);

if (nChoice == 4)

{

     myScriptObject.LockAllFields(form1); // calling Paul Guerette's script object.

     this.presence = "invisible"; // hides the lock button

     xfa.host.messageBox("The form is now locked, please remember to make sure you save it with a different name", "Customer quotes", 3, 0);

} //close if statement.

Have a search for "LockAllFields" in the forum.
Good luck,
Niall

Avatar

Level 2

Have just now downloaded revision.  Thank you so much taking a look at this!

Avatar

Level 2

Niall:

I can't thank you enough for your assistance!  I so owe you!  That is an absolutely wonderful script ...... I can see a need for it on all our forms.  Should I use this on another form, is there anything I need to specifically watch for to make sure I change within the script?

Again, many, many, many thanks!  : )

Avatar

Level 2

Niall:

I'm really embarrassed to even ask this question. But I was sampling the script on just another test document. Perhaps I've worked too long at this today and am too tired......but, how do you get the variable script into the document hierarchy? On my new test document (within the hierarchy), I don't even have a variables group. What am I missing?

Avatar

Level 10

No problem, glad you got it working. It really is Paul's script object, we're just implementing it in your form.

When you have a form open you can right client the parent/root node (automaticaly called "form1", but you can rename this). From the menu select "Insert script object".

script1.png

This will insert the "Variables" nodes and an unnamed script object. You must give the script a name, so that you can reference it in script. Also the script object should be a different name to the functions inside the script object. Please note that script objects can only accept Javascript, you will not be able to use FormCalc inside a script object.

script2.png

You can copy and paste from the other form into this new script object.

Another approach is to go back to the form that is working and drag the script object into the Fragment Library (tab next to the object Library):

script3.png

You can then drag the script object fragment into all of your other forms. When a fragment is dragged into a form, the script is grayed out because the script resided in the original fragment. Unless you are in a server environment (with LC ES) then I would recommend that you right click on the fragment and select "Convert to Embedded Object ".

script4.png

This will get you back to a fully editable script object.

Hope that helps,

Niall

Avatar

Level 2

Naill:

Thank you so much! I so appreciate all of your assistance.