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.

Check for empty field

Avatar

Level 2

Hi,

please help me with this question I have.

I have made a form in Livecycle Designer with a lot of textfields that needs to be filled. Most of those fields are mandatory. What I actually want to make is that after the user clicks a button like "Save" THEN there will be a check if all required fields are filled.

I have tried the function execValidate but I don't want to use that. Because then there will be popups at other moments, than at the save-moment.

I was thinking something like:

if (Form1.Page1.SubForm1.CustomerName.RawValue.length == 0) then
{
xfa.host.messageBox ("Please fill this field",1,0);
}

but that does not seem to work.... Please help!

8 Replies

Avatar

Level 2

A few things to check for :

make sure that the form is not set to target version : Acrobat 7.

some scripts fail on that version. try to keep it Acrobat 8 Above.

This setting can be found under File > Form properties - under Default and Preview sections

Secondly: make sure that the form preview type is indeed dynamic, and that the form has been saved as a dynamic PDF form.

Some times the preview doesn't work unless the form has been saved.

Thirdly:

check if the designer REPORT tool is showing any exceptions, when you validate your script.

Lastly:

try to run the form in Acrobat - open the debugger using Ctrl + J and see if there are any run time script failures.

Avatar

Level 9

Hello ,

In my opinion you have to put your script in the change event of the save button . For example say you got a "TextField1" . What you need to do is to put some scripts for the field . (Like this you have to put the script for all those fields which you want to be mandatory).Dont specify the fields as required during building the form .

Button Save : onChange Event .

if (this.rawValue == true)

{

Form1.Page1.SubForm1.TextField1.mandatory= "error";

}

else

{

    Form1.Page1.SubForm1.TextField1.validate.nullTest = "disabled";

}

If you want you can also add an alert like app.alert("The red marked fields can't left blank").This alert should be in the change event after executing the validate test . If it fails try this in onClick event too.

Thanks.

Bibhu

Avatar

Level 2

Thanks for your response! I did put the code in the ButtonSave::click event.

Avatar

Level 2

Thank you all for your help!

I have put the script into the ButtonSave::change event. However, nothing happens, when I click the button (not in the Reader of Acrobat).

Could it be a problem if the Save-button is placed in a different subform than the fields that need to be validated?

Best regards,

Erik

Avatar

Level 9

Hello ,

I guess there is a problem in accessing the fields due to subforms . What you can do here is to try with resolve node method.

Suppose there is field called Textfield 1. Click on the field in the design panel . Then select the script to all events . Then you can see a certain code comes in the javascript editor . Just copy that .Now type xfa.resolveNode("The copied content from the script editor").mandatory = error .(As per your requirement).

Thanks.

Bibhu

Avatar

Level 10

If your Save button is of type Regular then place the below code in the click event. If your button type is of Submit then place the below code in preSubmit event.

Language is Java Script:

if (Form1.Page1.SubForm1.CustomerName.rawValue == null) {
     xfa.host.messageBox ("Please fill this field",1,0);
}

I am assuming the path of your CustomerName field is "Form1.Page1.SubForm1.CustomerName"..Otherwise correct the path.

Let me know if you have any issues..

Thanks

Srini

Avatar

Level 2

Thanks again!

I'll try your suggestions and post the results

Best regards,

Erik