Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Returning true / false when using scripts in the validate event

Avatar

Level 4
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
4 Replies

Avatar

Former Community Member
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

Level 4
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

Former Community Member
Do not use the keyword return...simply use true or false.



Like this:

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

true;

} else {

false;

}

Avatar

Level 4
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