Javascript code for multiple if/then conditions Livecycle Designer

akgrimes

15-12-2016

I'm trying to code a button that will check several mandatory fields and individually highlight them in red if they aren't completed. I do not want to use a submit button.

I can get the code to work for my first field:

if ( form1.pageonesubform.Topchunkpageone.agencyuseonlytable.Row3.typeofrequest.typeofrequestlist.isNull)

{   

form1.pageonesubform.Topchunkpageone.agencyuseonlytable.Row3.typeofrequest.typeofrequestlist.border.fill.color.value = "255,0,0";     xfa.host.messageBox("Some fields are empty. Please scroll up and complete fields highlighted in red.");    

}

else {

form1.pageonesubform.Topchunkpageone.agencyuseonlytable.Row3.typeofrequest.typeofrequestlist.border.fill.color.value = "255,255,255"; 

}

But where do I put code for the next if/else? When I set up the exact same code with the next field name under the above if/else code, nothing at all happens -- the first action doesn't even happen. But if I make it "or" with ||, then it will only highlight one field -- the first one.

I need it to do this:

If typeofrequestlist is empty, turn it red, once filled, turn it white

AND

If supvname is empty, turn it red, once filled turn it white

AND

if supvclass is empty, turn it red, once filled turn it white

//and so on

then

If all fields are filled, show message box "All mandatory fields have been completed."

HELP.

Accepted Solutions (1)

Accepted Solutions (1)

Magus069

MVP

16-12-2016

*** By using the operator || you will only verify the next statements only if the first statement is false...

*** By using the operator | you will verify each statements, even if it's true or false

I wanted to specify this statement about the operators to make sure you don't get mixed up between the two different possibilities...

If you want to have your own validation without having to use a submit button with Adobe Validation, I have custom made a function which validates all visible fields within any PDF. Have a look if this could help you save time and also it is easy to manipulate the validation.

Validation / Reset Functions, easy to manipulate and to change Forms!!!!

Answers (4)

Answers (4)

Magus069

MVP

16-12-2016

You have to download the PDF on your PC to be able to open it with LiveCycle Designer... Adobe Reader in a browser will not work with this dynamic PDF.

_Bruce_Robertson

MVP

15-12-2016

Hi,

I think your approach is ok, but maybe you just have an error in your code.  In Acrobat under Edit ... Preferences ... JavaScript, set "when exception is thrown" to break and the JavaScript console will display if there is an exception.

In the script editor you can generate the reference to your fields.  Place your cursor in the Script Editor where you want your reference to appear, then go back to the form and select the object while holding down the Ctrl key and the reference will inserted into your Script.  Because your references are so long it looks like you have typed them in which would make it easy to make a mistake.

If you are still having problems, upload your form somewhere like DropBox or Google Docs, and post a link in this thread and we can have a look.

Regards

Bruce