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.

Making a field mandatory

Avatar

Former Community Member
We've designed a form for print output and want to make several fields mandatory. Selecting the option "User Entered - Required" and setting the Empty Message field does not cause any errors when the user tabs out of the field. Does that option only work for forms that are being submitted via email?



Tom
22 Replies

Avatar

Former Community Member
Hi Tom,



This was taken from the Designer help:



"Users cannot submit a PDF form containing null values when those values are required. However, users can save and close a PDF form without providing recommended or required values. In this case, no messages appear to prompt users for input."



But, you can script a pop up to remind the users using an app.alert, or you can script so that the form won't save/print unless those fields are filled out, etc.. it would all depend on the circumstances.



Hope that helps,



Catherine

Adobe Systems

Avatar

Former Community Member
Thank Catherine. I guess the Designer help is a little misleading! Under "Text field properties in the Value tab" it says "User Entered - Required If the user does not enter data, a custom message (if written in the Empty Message box) appears."



Do I need to attach a script to my print button or to the fields I want to be mandatory? Should it be for the prePrint event? Is there any more documentation about scripting on the Adobe web site than there is in the Designer's Help?



Tom

Avatar

Former Community Member
Just for the records: we see the same issue as well.



And even worse, we can even submit documents containing empty required fields, so this looks like a bug in AR to me.

Avatar

Former Community Member
Tom,



It would all depend on whether you wanted to verify all the fields at the end, or as you go through the form. This would be a design decision that you would make. Either way would work.



As for more documentation, see below. I'm not sure if you already have this or not.



Let me know if this helps,



Catherine

Adobe Systems

Avatar

Former Community Member
I have made a field User Entered - Required and input a Message, then I put in a validation in javascript as follows:



if(this.rawValue==null){xfa.host.setFocus(this.name);}



So long as you place your cursor in this field, it will not let you exit the field without inputting information. But if you skip the field altogether it ignores it.



This is better than before, the only problem is that I keep getting a warning message when I test it. Message is as follows:



Generating PDF Document...

Script failed (language is javascript; context is xfa[0].form[0].form1[0].#subform[0].VendorInfo[0].payToTheOrderOf[0])

script=if(this.rawValue==null){xfa.host.setFocus(this.name);}

Error: $host does not have a method 'setFocus'

PDF generated successfully.



Should I be inputting something different for 'host' or 'setFocus', and if so, what?



Susan de Graaf

Avatar

Former Community Member
Hi Susan,



Here is a code snippet that works for me:



if(TextField1.rawValue == null){

xfa.host.setFocus("xfa.form.form1.TextField1");

}



I think that your problem is that the parameter for the setFocus function should be a string. Check out the Attachment I posted in this topic, that should help you.



Catherine

Adobe Systems

Avatar

Former Community Member
I get that warning message too. Sounds like the warning is a bug to me, your script should be fine. I'll look into it and get it logged if need be. I think you should be able to safely ignore the warning and it will work fine, does it not?



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Hello Catherine,



I was unable to find the attachment to which you referred in your posting to Susan. Can you direct me?



Thank you.



Howard

Avatar

Former Community Member
Hi Howard,



You can find this PDF reference at the following site: http://partners.adobe.com/public/developer/livecycle/designer/devcenter.html



It is called the Adobe XML Form Object Model (PDF), it is near the bottom of the page.



Let me know if you have problems finding it.



Catherine

Adobe Systems

Avatar

Former Community Member
Many thanks for the incredibly rapid response.



Howard

Avatar

Former Community Member
I've got a related issue - requiring entry of a drop-down option, with the first option (value=0) not being allowed as a valid selection. Has anyone conquered that issue?



Thanks-

Kim

Avatar

Former Community Member
You can do this with some simple JavaScript in the drop down list's Change event.



The key here is to use the xfa.event.change and xfa.event.newText variables of the xfa.event object in the Change event which contain the text which will be assigned to the list after the event completes. If you detect that the value item bound to the xfa.event.newText variable is 0:



if (this.boundItem(xfa.event.newText) == "0")


then you can use the current value of the drop down list:



this.rawValue


to determine which value to assign to the xfa.event.change variable in order to prevent the selection from changing.



Since this is a little complicated to explain in words, I've attached a sample form which demonstrates this technique. Check-out the script in the drop down list's Change event.



Stefan

Adobe Systems

Avatar

Former Community Member
That is helpful, but I still have some questions.



I've created a form with required text fields. These fields are set to be highlighted if the user tries to print the form with nothing in those fields.



There are 2 required dropdown lists in the form, as well. I need to have them validate with the other fields in the click event (script below) or not allow the user to exit the field until a valid option is selected. I had tried the following script (from an earlier message in this topic) in the field's exit event, and got close to what I need:



if(fdType.rawValue == null) {

xfa.host.setFocus("xfa.form.form1.fdType");

}



Maybe the above script should be linked to a different event? To add to the issue, I have fields highlighted on enter and the highlight disappearing on exit. The script above worked except for allowing an invalid option being selected (which the attachment would correct) and leaving the field highlighted even after it was exited.



I guess what I need is a way to combine the several parts into a working whole. Any help is greatly appreciated!!



click script:



var iVar=0;



if ((fdName.rawValue==null) || (fdName.rawValue=="")) {

app.alert("Please enter the fund name.");



// Change color of fillable area of text field.

xfa.resolveNode("fdName.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("fdName.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("fdName.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("fdName.ui.#textEdit.border.fill.color").value="255,255,255";

}



if ((donorInfo.rawValue==null) || (donorInfo.rawValue=="")) {

app.alert("Please enter donor restrictions/instructions.");



// Change color of fillable area of text field.

xfa.resolveNode("donorInfo.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("donorInfo.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("donorInfo.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("donorInfo.ui.#textEdit.border.fill.color").value="255,255,255";

}



if ((dept.rawValue==null) || (dept.rawValue=="")) {

app.alert("Please enter the department.");



// Change color of fillable area of text field.

xfa.resolveNode("dept.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("dept.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("dept.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("dept.ui.#textEdit.border.fill.color").value="255,255,255";

}



if ((fdAdmin.rawValue==null) || (fdAdmin.rawValue=="")) {

app.alert("Please enter the fund administrator.");



// Change color of fillable area of text field.

xfa.resolveNode("fdAdmin.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("fdAdmin.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("fdAdmin.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("fdAdmin.ui.#textEdit.border.fill.color").value="255,255,255";

}



if ((subName.rawValue==null) || (subName.rawValue=="")) {

app.alert("Please enter your name.");



// Change color of fillable area of text field.

xfa.resolveNode("subName.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("subName.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("subName.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("subName.ui.#textEdit.border.fill.color").value="255,255,255";

}



if ((subTitle.rawValue==null) || (subTitle.rawValue=="")) {

app.alert("Please enter your title.");



// Change color of fillable area of text field.

xfa.resolveNode("subTitle.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("subTitle.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("subTitle.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("subTitle.ui.#textEdit.border.fill.color").value="255,255,255";

}



if ((subEmail.rawValue==null) || (subEmail.rawValue=="")) {

app.alert("Please enter your email address.");



// Change color of fillable area of text field.

xfa.resolveNode("subEmail.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("subEmail.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("subEmail.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("subEmail.ui.#textEdit.border.fill.color").value="255,255,255";

}



if ((subTel.rawValue==null) || (subTel.rawValue=="")) {

app.alert("Please enter your phone number/extension.");



// Change color of fillable area of text field.

xfa.resolveNode("subTel.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("subTel.ui.#textEdit.border.fill.color").value="255,0,0";



// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset fillable area of text field.

xfa.resolveNode("subTel.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("subTel.ui.#textEdit.border.fill.color").value="255,255,255";

}



// If all required fields contain data, iVar is set to zero and form prints.



if (iVar==0) {

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 1, 0, 0, 0);

}

Avatar

Former Community Member
From what I can see in your post, your validation script seems to be OK. Is there a reason why you didn't try to validate the drop down lists in the same fashion (i.e. by checking that their rawValue isn't null and isn't an empty string)? That should work just like any other field.



As for setting focus back to the drop down list which was left empty, I've attached a form which I created for another post (can't remember which one anymore) which demonstrates how to set focus back to a field that's required when it's left empty. See the Exit event script on the SSN field.



Stefan

Adobe Systems

Avatar

Former Community Member
I did try to validate the same way, but couldn't get it to work. What would I have to modify in the code to get it to highlight and empty dropdown field?



if ((fdType.rawValue==null) || (fdType.rawValue=="")) {

// Change color of border/highlight field.

xfa.resolveNode("fdType.ui.#textEdit.border.edge").stroke="solid";

xfa.resolveNode("fdType.ui.#textEdit.border.fill.color").value="255,0,0";

// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset field.

xfa.resolveNode("fdType.ui.#textEdit.border.edge").stroke="lowered";

xfa.resolveNode("fdType.ui.#textEdit.border.fill.color").value="255,255,255";

}



Thanks-

Kim

Avatar

Former Community Member
I think the problem lies in the object type you're specifying after the UI element. For a drop down list, it's
choiceList so the script should look like this:



if ((fdType.rawValue==null) || (fdType.rawValue=="")) {

// Change color of border/highlight field.

xfa.resolveNode("fdType.ui.
#choiceList.border.edge").stroke="solid";

xfa.resolveNode("fdType.ui.
#choiceList.border.fill.color").value="255,0,0";

// Set variable to indicate that field does not contain data.

iVar=1;

}

else {

// Reset field.

xfa.resolveNode("fdType.ui.
#choiceList.border.edge").stroke="lowered";

xfa.resolveNode("fdType.ui.
#choiceList.border.fill.color").value="255,255,255";

}



Give that a try and let me know how it goes!



Stefan

Adobe Systems

Avatar

Former Community Member
That was it! Thanks for your patience and help.

Kim

Avatar

Former Community Member
I tried adding this javascript for validate in livecycle to make this field check for content before allowing the user to go to the next field but it does not work.

The field name is DEPARTMENTOFFICE



if(DEPARTMENTOFFICE.rawValue == null){

xfa.host.setFocus("xfa.form.form1.DEPARTMENTOFFICE");

}



The pdf is new_vendor_data_form.pdf



I am not good at scripting. What is it that I am leaving out?



Thanks

Avatar

Former Community Member
Did you try adding following in EXIT event of the control you are validating?



it can look something like:



if(this.rawValue == null){

xfa.host.setFocus($.somExpression);

}

Avatar

Former Community Member
I set some fields as User Entered - Required, and entered some text that should appear if the user tries to tab out without entering anything. It didn't work (as mentioned by others on this thread). However, I noticed that if I entered something in the required field and then deleted the entry, and then tried to tab out of the field, the error message appeared, and it wouldn't let me tab out of the field. So this seems to be a bug.



I read some of the posts in this thread about writing script, but unfortunately my computer expertise is not at that level. I don't even know where to place the script. Help!



Thank you.