Expand my Community achievements bar.

SOLVED

Validate Control

Avatar

Level 3

I'm using LiveCycle Designer 8.

I have an Image field in a form with a validation java script that checks the size of the image that the user is adding. If the image is over 1MB, I issue a warning, but leave the image. There is no problem there.

However, after the file is saved and upon opening the PDF, the LCD seems to run through all the validate scripts and therefore, issues the size warning.

Any ideas how I can avoid the warning when the form is opened?

All suggestions are appreciated....

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi David,

While you can use a textfield to act as a flag, I find it easier to use a numeric field with "1" for on and "0" for off.

You could try putting the script for the image field in the mouseUp event, but I don't think it will work because at mouseUp Acrobat opens the dialogue window to select the image.

I think Paul's solution is based on:

  1. the default value of the flag is "0" (no validation);
  2. having an If statement on the exit event of the image field. If the image is greater than 1Mb it sets the flag to 1.
  3. on the change event of the flag, another if statement to run the validation if its value is "1"

You would potentially need a flag for each image field.

I stand to be corrected   ;-)

N.

View solution in original post

11 Replies

Avatar

Former Community Member

What event did you run your code on to give the warning in the 1st place?

Paul

Avatar

Level 3

Thank you for your question.

It's in the validation event

Avatar

Former Community Member

The validate event will fire each time you open the form. Move the code to another event that will only fire when the user does something (i.e. the exit event).

Paul

Avatar

Level 3

Thank you for the feedback.

I did move the code to the exit event, but from an end-user perspective, I found this a bit confusion. For example, I have the imagefield (photo) and a text field (title),

If the user adds an image that is too big and I put the code in the exit event (nothing happens), then when they click on the title field, they get the imagefield message.

If there a way with java script to put code in the function that might say something like, "if the user is on this imagefield, then check for size, otherwise, don't check?

Avatar

Former Community Member

You could set a flag in another field when the user sets the image then check the status of the flag to see if you should display the message of not.

Paul

Avatar

Level 3

Getting close....

Because I'm a newbie, I'm not sure how to change the value of a different field and I will need this for your suggestion to work.

To make it simply, assume that I have two fields MyFirst and MySecond.

Assume that I'm on the first field (MyFirst). What would I put in the calculate event to change MySecond to, say "abc"

Thank you for your help.

Avatar

Former Community Member

It is as simple as this:

MySecond.rawValue = "Vlaue that you want to set"

Paul

Avatar

Level 3

Thank you the feedback.

My problem here was that when I created my objects, I used dashes in the names, as in "My-First-TextField" and this caused all kinds of problems -- problems that you don't want to wrestle with when you are learning something new!

Since renaming all my objects, most of these problems have disappeared.

Thanks again.

Avatar

Level 3

Thanks Paul,

This is the way I need to go here. However, this is proving more difficult that it first looks.

I created a variable called JustOpened and set the initial value to "yes"

In my validate routine, I set JustOpened to "no" and then call my function.

This does not work because, as you indicate, the validate function is called when the form opens.

I like the idea of having the JustOpened variable and I think that having the default set to "yes" could work. However, where could I set JustOpened to "no" so that my validation works as intended?

Avatar

Correct answer by
Level 10

Hi David,

While you can use a textfield to act as a flag, I find it easier to use a numeric field with "1" for on and "0" for off.

You could try putting the script for the image field in the mouseUp event, but I don't think it will work because at mouseUp Acrobat opens the dialogue window to select the image.

I think Paul's solution is based on:

  1. the default value of the flag is "0" (no validation);
  2. having an If statement on the exit event of the image field. If the image is greater than 1Mb it sets the flag to 1.
  3. on the change event of the flag, another if statement to run the validation if its value is "1"

You would potentially need a flag for each image field.

I stand to be corrected   ;-)

N.

Avatar

Level 3

Resolved...finally!

To resolve this I setup a variable (File, Form-Properties) called JustOpened. I set the default value to "yes"

I then put JustOpened.value = "no" in a form:ready event (you can use any object for this).

I then put JustOpened.value = "yes" in the DocClose event (you can use any object for this too).

In my validate function, I only execute the validate code if JutOpened = "no."

Works like a charm.

What I learned through this is that each object has associated with it, a list of (I think they are methods) methods that are executed when the form is opened. They include Initiate, Calculate, Validate, FormReady, and LayoutReady. In addition, everytime a user edits a form field, the LayoutReady method is executed. Understanding this makes a HUGE difference when coding a form.

Thanks for the help....