2 Replies Latest reply on Oct 4, 2011 1:37 PM by JLAFARGUE

    Setting the Access of a subform

    JLAFARGUE

      I'm trying to set the access of a subform based on the value of a checkbox in another subform.    In the change event of the checkbox, if the rawValue == 1, then I attempt to set the access of the second subform to "protected".  If the rawValue == 0, I set the access of the second subform to "open". 

       

      What actually happens is that the access of the second subform is unchanged.   In fact, when I try to even display the value of the access attribute of the second subform from the change event of the checkbox, the value displays a s null.  What am I doing wrong?

       

      Here's the code that sets the access:  ('this' is the checkbox.)

       

      if  (this.rawValue == 1) {

           parent.parent.subform2.access = "protected';

      }

      else {

           parent.parent.subform2.access = "open";

      }

       

      The hierarchy is this:

       

      Mainform

           subform1

                checkbox

           subform2

                < Other Objects>

       

      Subform2 is a repeatable subform, so when I set the access to "protected", I also want to remove all instances except the first one. 

        • 1. Re: Setting the Access of a subform
          Steve L Walker Level 5

          First, what event are you coding against?

           

          Second, I'd recommend removing parent references in this use case and point directly at the subform.

           

          // form1.page1.subform1.cb::click - (JavaScript, client)

           

          if (this.rawValue == 1) {

                    form1.page1.subform2.access = "protected";

          }

          else {

                    form1.page1.subform2.access = "open";

          }

           

          Steve

          • 2. Re: Setting the Access of a subform
            JLAFARGUE Level 1

            I tried removing the parent references and specifically referencing the subform but it didnt' work.  However, I did find out how to do it from a co-worker.  Here's how.

             

            In the checkbox change event of the checkbox  (this):

             

            if (this.rawValue == 1) { //1

                 var i = 0;

                 var ref = xfa.resolveNode("MainForm.PageN.Subform[" + i + "]");

                 ref.TextField.rawValue = null;                         //  repeat these two lines

                 ref.TextField.access = "protected";                //   for every field you want to reset and set unavailable.

             

            else {

             

                 ref.TextField.access = "open";                         // repeat this line for every field to set available.

             

            }

             

            I haven't figured out how to travel through the hierarchy to do this, so I will have to set the rawValue and access for each individual field.