Expand my Community achievements bar.

Access field in hidden subform

Avatar

Level 1

I apologize if this seems very basic question, but have not been able to find an answer yet.

I need to turn off a mandatory field inside a hidden subform. I can access the subform using the instance manager, but not any fields inside it.

I've tried something like this:

form1::preSubmit:form - (JavaScript, both)

if (page2.mainSub._branch2.count == 0){

     page2.mainSub._branch2._reqField.mandatory = "disabled";

}

I guess my other option would be to make every field not required and then set to mandatory when the subform becomes visible.

Appreciate any help.

Thanks,

Mark

4 Replies

Avatar

Level 10

You are checking for the Instance Manager count as 0. But ideally it will be 1 if you have any subform exists on the form whether visible or hidden.

Second, you are trying to access the Instance Manager of the reqField in your code (_reqField). May be you need to correct it.

Try the following code to fix your issue.

if (page2.mainSub._branch2.count == 1){

     page2.mainSub._branch2.reqField.mandatory = "disabled";

}

Thanks

Srini

Avatar

Level 1

Srini,

I appreciate the response. Maybe I am not understanding the count or underscore features. From my understanding, if the "count" is 1 then the subform is visible. In that case, the user can see the question and answer it as a required field. My problem is the subform is not visible (count of 0), but can be accessed using the underscore.

Maybe this simple case will clarifiy the problem:

Q1. Do you have a favorite color?

Radio: Yes/No

If "Yes" {

Q2a. What is it?

Text: {required}

}

if "No" {

Q2b. Why not?

Text: {required}

}


Both Q2 fields are hidden until Q1 is answered and then only the  appropriate branch shows. So, if they answer "Yes" to Q1, I need the "No" branch text field to no longer be required and vice versa.

So, "Yes" would have form1.form._Q2a.count as 1 and form1.form._Q2b.count as 0. I would think something like form1.form._Q2b.Text (or ._Text) would be a valid reference and I could change the "mandatory" property as I need. I've tried using the direct reference and using xfa.resolveNode to no avail.

Thanks,

Mark

Avatar

Level 10

Please find my answers below.

Maybe I am not understanding the count or underscore features. From my understanding, if the "count" is 1 then the subform is visible. In that case, the user can see the question and answer it as a required field. My problem is the subform is not visible (count of 0), but can be accessed using the underscore.

Srini:

     Making a subform Visible/ hidden will be done by changing a property value similar to changing the name of the subform. That means the Subform is actually avaiable in the form Heirarchy but you set the presence property to make it Hidden/ invisible.

     As long as the subform is available in the form Heirarchy, the minimum count will be 1.

     If you do not see the subform in the Heirarchy then the count will be 0. (OR) If you delete all the subform instances by using removeInstance method then the count will become 0.

     You can access the instanceManager of the subform using a underscrore. It is a short version of accessing it.

     For example: Both the below statements are correct.

          form1.form._Q2b.presence = "visible";

          form1.form.Q2b.instanceManager.presence = "visible";

But in your simple case you mentioned, you do not need to use an Instance Manager of the subform. You just need a way to hide and display the subforms based on user input for the previous question.

     With that your code may look like this..(You donot need to use underscore notation because you are not using the Instance Manager)

    

     if (page2.mainSub.branch2.presence == "hidden"){

          page2.mainSub.branch2.reqField.mandatory = "disabled";

     }

I have a put in a sample file for your reference with the similar logic. In my example, the subforms are present in the heirarchy. I am only hiding and displaying them based on the previous answer.

https://acrobat.com/#d=LlEgTgo3**oSPJlYGxGTKw

Thanks

Srini

Avatar

Level 1

Srini,

Thanks for the help, but I think I figured it out. "Hidden" may have been a misnomer. We are actually adding and removing instances using the instance manager. Once I remove the instance, I lose visibility into the fields within the removed instance. So, I'm going to have to go a different route.

Thanks again!

Mark