Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Making all hidden fields optional

Avatar

Level 2

Hi all!

 

This is related to a previous question that I've asked, but I think I narrowed things down quite a bit. I have a script (Fragment) that runs on submission that scans the form and makes all hidden-required fields optional, that way the form will submit as long as all of the visible required fields are filled. This script worked really well on PDF forms, but I'm transitioning to .xdp (HTML5 rendered) forms. 

 

I'm having 1 key issue. Whenever I try to change a hidden field to optional, the script crashes. My initial fix was to, in the script code, make the field visible, make it optional, then make it hidden. This briefly worked but now is broken for some unknown reason. It makes the user push submit twice before submitting, obviously not great from a user experience standpoint.

 

Is there a known way to make a hidden field optional in a script? This seems like something that lots of people would want to do, but I can't find anything about it which leads me to worry that maybe I'm missing something obvious. Thank you for any advice you can give!

 

Respectfully,

John

4 Replies

Avatar

Employee Advisor

@JohnSolomon0 instead of making the field required you can actually prefer this logic:

if(field visible==true){

//check if the value is not null.

TextField1.validate.nullTest = "error";

}

You can also use one of these two scripts:

    TextField1.mandatory = "error"  
    TextField1.mandatoryMessage = "this field is mandatory!" 

https://help.adobe.com/en_US/livecycle/10.0/DesignerScriptingBasics/WS92d06802c76abadb57cc1b6e12a923...

Avatar

Level 2

Hi Mayank,

 

I have way too many hidden required fields across my implementation of Webforms for it to be reasonable to go in and do that logic on each one of them. I need a way to solve this in a fragment script. 

 

I've tried using that bit

TextField1.mandatory = "error"  

but when I try and do that to a hidden field it doesn't work. 

 

I engaged Adobe support and we found a workaround, but I'm still confused as to why that doesn't work. 

Avatar

Employee Advisor

"we found a workaround," and that doesn't work? I am a bit confused so how is that a workaround or is it not consistent? 

Avatar

Level 2

Just making the .mandatory= "disbaled" or "error" doesn't work. You have to first do the process I described originally where you make it visible, then modify the .mandatory property, then make it hidden again.

 

You also can't call the fragment that does this from the validate event (where we were originally calling it. The only event you can call it from is the "preSubmit" event. 

 

On top of that, if it does succeed, you have to modify the event handler like so: 

if(!clientChangeScriptsHTML.validateForm())
{
xfa.event.cancelAction = 1;
}

 

and you also have to make sure that that code is in a field not a subform, otherwise it runs twice.

 

 

So. Instead of being able to just modify the mandatory field property in a fragment script, you have to

 

1. Make sure that the field is visible BEFORE modifying it. If it's invisible or hidden or anything else it won't work.

2. Make sure that the form object that calls the fragment script is not a subform, it has to be a field.

3. Make sure that the event that calls the fragment script is on the "preSubmit" event rather than the "validate" event (which is where validation code is supposed to go), otherwise it won't work. 

4. After calling the script if the script was successful you need to modify the event handler with xfa.event.cancelAction = 1;

 

I understand that we're getting in to custom coding here, and that workaround that incorporates those four factors works, but I don't understand the first point. Why do I have to make the field "visible" before I can modify the mandatory property? If I attempt to modify the mandatory property while the field is hidden the entire script just won't work.