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.

Hiding Fields of a form when form loads, based on the value of another field

Avatar

Level 3
Hi,

I have a form which deploys through Workflow in which I need to hide or show fields, or groups, based on which step the workflow is on.



Example:

A form to request a new computer. It gathers the data required for the user and then goes to the Help Desk. The Help Desk does their job and then fills a checkbox to say it was completed. In the first step we don't want to see the Completed checkbox, but when it gets to the Help Desk we do.



My attempt:

I tried to do this by using the SetValue QPAC to set a field on the form to "MIS", the problem here is that the data is entered after the initialization of the form.



Help...
8 Replies

Avatar

Former Community Member
Hi Robert -



I think you're using the correct approach. My question for you is - what form event are you putting the script that will hide the checkbox? I think the Form:Initialize event would be the right place, as I think this event happens once data is loaded.



If this doesn't work you could try other events like the ready event, or post your question to the Forms forum.



Good luck!



Will

Avatar

Level 9
Hi Robert

I agree with Will, I think you're on the right track. The other event we've found useful is the form:ready event, which is fired just before the form is displayed.

Also, make sure you save your form as a dynamic PDF prior to saving it as an XDP, otherwise hide/show logic won't work.



Howard

http://www.avoka.com

Avatar

Level 3
Thanks guys,

I have tried the initialize event on the form, and it returns that my properties are null or not an object, such as "ServiceRequest.Computer.Completed is null or not an object." on the line 'ServiceRequest.Computer.Completed.presence = "hidden";'



And the Form:Ready event never appears to actually fire. I am using HTML render, not PDF, which may be why that one never fires, I think I read something about that.



Unfortunately I still have not been able to find a solution to my problem; I shall try the Forms forum as you suggested, Will.



Thanks again,

Rob Veldpaus

Avatar

Former Community Member
Hi Robert,



You are correct that Form:Ready does not fire when rendering in HTML.



A possible cause for your issue is that, unlike PDF rendering, not all objects that are in your form at design time will be rendered in HTML.



By this, not only do I mean that the object is not visible, but that the object will not exist in the browser context.



Attempting to access such an object, including its presence attribute, would cause the error message that you posted.



Please see below for a non-exhaustive list of scenarios where an object is not rendered in HTML:



- Object's Presence is set to 'Hidden' at design time

- Any subform's Presence from the object up through the hierarchy to the root is set to 'Hidden' at design time

- Object is not contained by a Body Page in your hierarchy

- Object is a Script Object



Please note:



- An object with Presence set to 'Invisible' at design time is rendered in HTML (although it will not be visible)

- Once an object is rendered in HTML, it can have its presence attribute manipulated by client-side script through all states, including 'hidden'. This behaviour is consistent with PDF.



Ben



http://www.avoka.com

Avatar

Level 3
Actually, I have this problem, even with the Click event. I am trying to make a checkbox, when it is clicked, check a field that is three levels higher (this.parent.parent.parent.Blah.rawValue). It gives me the same "Object is null" error.



The object is not hidden, and does not fall into any of those other categories that Ben listed.

Avatar

Level 9
Hi Robert



Send your form to info-at-avoka.com, we'll take a look.



Howard

Avatar

Former Community Member
Hi Robert,



As you have confirmed that the object is being rendered in HTML, I would suggest that the next factor to examine is the way that you are referencing that object.



In your example above, is 'Blah' an object name? If so, I would not expect this to work. With HTML rendering it is generally best to always reference an object by the xfa.resolveNode or xfa.resolveNodes constructs. Although, the this.parent construct does give a reference to parent objects, the [object].objectName construct does not work.



Although the object string identifier (SOM expression) that you provide the resolveNode function can be relative e.g.



xfa.resolveNode("sSubform.txtTextField")



for troubleshooting, I suggest that you try using the full qualified SOM e.g.



xfa.resolveNode("form1.page1.sSubform.txtTextField")



To ensure that the object reference is correct, try using the auto object reference feature: click the cursor inside a script, hold the ctr key and hover the mouse over the object on the Body Page. When the pointer turns to a V, click the object.



Regards,



Ben



http://www.avoka.com



P.S. I am offering this advice without having seen your form.

Avatar

Level 3
Hi Ben,

Thanks for your help, this is exactly what I needed.