Returning true / false when using scripts in the validate event

Avatar

Avatar
Boost 1
Level 4
Thomas_McConnac
Level 4

Likes

2 likes

Total Posts

134 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 4
Thomas_McConnac
Level 4

Likes

2 likes

Total Posts

134 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
Thomas_McConnac
Level 4

09-02-2009

Hi all,



I'm using a script in teh validate event to determine a false or true response and then when all the checking has been done I use:



if (matchFound) {

return true;

}



However this is coming up with the error message:



Error: Illegal 'return' outside of a function body, Line:21



Now obviously this means my return is in the wrong place, but where should it go? How can you pass on that a validate script, inside the event, has failed when using execValidate?



Many thanks,



Tom

Replies

Avatar

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

198 likes

Total Posts

1,435 posts

Correct reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

198 likes

Total Posts

1,435 posts

Correct reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
Steve_L_Walker
Level 9

09-02-2009

Tom,



execValidate() does not have a return value. Should "if (matchFound) { return true; }" exist within a validate event you will not get a boolean response.



http://livedocs.adobe.com/livecycle/8.2/acrobat_designer/001693.html



To do the type of validation you are hinting at requires an alternative approach. You could consider using script objects.



Steve

Avatar

Avatar
Boost 1
Level 4
Thomas_McConnac
Level 4

Likes

2 likes

Total Posts

134 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 4
Thomas_McConnac
Level 4

Likes

2 likes

Total Posts

134 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
Thomas_McConnac
Level 4

10-02-2009

Steve,



By wrapping the execute in an if statement you can tell if it managed to execute correctly or failed.



if (this.parent.parent.execValidate()) {

this.parent.parent.presence = "hidden";

Question2.presence = "visible";

xfa.host.setFocus("Header.FocusField");

}



Will only move on to the next question if the form addressed(this.parent.parent) has validated correctly.



The problem I am having is that I wanted to use the validate event to check if a field contained a valid entry.



http://livedocs.adobe.com/livecycle/8.2/acrobat_designer/wwhelp/wwhimpl/js/html/wwhelp.htm?href=0010...



This quite clearly says that you can return a false or true:



"Calculations and scripts on the validate event are required to return true or false (expressed in a format appropriate to the scripting language) corresponding to a validation that succeeds or fails, and must not affect the overall form structure of form values."



But when I try to return a true or false it tells me I can't.



As I have a deadline to get this done I will be forced to run this in a scripting object, but I don't understand the reason for having a validate event at all if you cannot tell if that validate event succeeded.



Tom

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

10-02-2009

Do not use the keyword return...simply use true or false.



Like this:

if (this.rawValue == "Paul"){

true;

} else {

false;

}

Avatar

Avatar
Boost 1
Level 4
Thomas_McConnac
Level 4

Likes

2 likes

Total Posts

134 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 4
Thomas_McConnac
Level 4

Likes

2 likes

Total Posts

134 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
Thomas_McConnac
Level 4

10-02-2009

Thank you Paul!



Legend as always. Not going to go back through my form though, deadline is up and I've had to fix it with scripting objects 😞



Tom