Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

setFocus and closeDoc

Avatar

Level 2

Hi experts,

I have a form with some required fields.

I've implemented a function that checks for each field (on exit event) if that field was filled or not;

if not, a message is raised and the current field is focused again until it's not filled as expected.

The problem is that, if the user tries to close the document, the check function is executed a lot of times (and the message raised) until adobe reader crashes!

Any suggestion on how to solve that problem?

Best regards.

Dariush.

1 Accepted Solution

Avatar

Correct answer by
Level 10

If you want to do that you will not be able to take advantage if the validation features that are supplied for you . You will have to write your own validation code for that field on the exit event of you field.

Hope that helps

Paul

View solution in original post

11 Replies

Avatar

Level 2

Just providing more info,

here my jscript code for the required field, on exit event.

if (!this.execValidate()) {

                    xfa.host.setFocus(this);

}

This field has an 'Empty message' and 'Validation script message', thus if the execValidate fails a messagebox is reaised by the reader.

any suggestions? Best regards,

Dariush.

Avatar

Level 10

If you set the field as required then there is no need to check to see if it is filled or not. Thats what making a field required means. It will not allow you to submit the form until all required fields are filled. If you want to make sure that all fields are filled before a save is done or a print is done then you can put code on the preprint and presave event that will execute all validate events:

form1.execValidate()

Paul

Avatar

Level 2

Hi Paul,

thank you for the answer,

I know a form.execValidate can be executed before printing/submitting, the problem is that the form has a large number of fields and the customer would have a direct feedback once the field is exited.

Any best practice regarding?

Ciao, dariush.

Avatar

Level 10

So put your code on the exit event and not the validate event ….the validate will fire when the form loads and when the form is submitted …..you are causing all of these additional events to fire for nothing.

Paul

Avatar

Level 2

Paul,

my code is in the field exit event, not on validate event.

Take a look please

-------------

PAGE.Page1.w_intcoint::exit - (JavaScript, client)

if (!this.execValidate()) {

                    xfa.host.setFocus(this);

}

---------------

If I try to close the pdf doc while I'm in w_intcoint field and I've not filled the field, the reader shows 2 or 3 times the required message then crashes.

If you want I can send you a quick sample.

Dariush.

Avatar

Level 10

Sorry my bad!

I do not like the idea of firing other events to do your code ......why not simply do your validation check on the exit event script?

Paul

Avatar

Level 2

I'd not solve the problem.

Once I force the 'focus' on the field until it's not filled, I'm not able to close the doc because selecting file->close, or using [x], the script assigned to that field is runned, the message is raised and the document is not closed immediatly, but only after 2 or 3 messages and after a reader crash.

I don't know at this point if I explained in a proper way my problem, If not Paul tell me, I'll retry 🙂

Dariush.

Avatar

Level 2

btw,

here an example of what I've implemented.

Surely there's sth wrong, but I don't understand how let this working properly.

http://dl.dropbox.com/u/21852816/test.pdf

Best regards,

Dariush.

Avatar

Level 10

You hav eput yourself into an infinite loop ....when you leave the field your exit event fires which causes your validate event to fire but before that is started the cursor is placed back in the field. The message comes up and you click on teh message to dismiss it. This causes the exit event to fire and the whole process starts over again. You can proove this by adding an app alert to the exit and validate event indicating that the event has fired .....there you can see when then evetns are firing and you will see what I mean.

Paul

Avatar

Level 2

I see Paul,

this means that the message box raised is not blocking, now I understand.

So, can you suggest me (I'm sure there's a good way) a best practice to check the required field once the user exits from it and force him to stay in that field until the field is filled as expected?

Obvioulsy if the user tries to close the document it should close without an crash.

Let me know please and thank you again.

Dariush.

Avatar

Correct answer by
Level 10

If you want to do that you will not be able to take advantage if the validation features that are supplied for you . You will have to write your own validation code for that field on the exit event of you field.

Hope that helps

Paul