1 Reply Latest reply: Aug 16, 2012 5:23 AM by BR001 RSS

    How do I use javascript or formcalc to reference child controls (not by name)

    past-tense Community Member

      Hi everyone,

       

      I've created a ton of reports in the past, and I'm now looking at creating some reusable objects so that other people can use advanced form functionality without having to learn to use scripts.

       

      A lot of the coding was acheived using this, .parent, etc. so that they can rename controls and subforms without having to worry about breaking scripts. One issue that I am having is that Some of my code looks at children controls, and references them by name (for example, I have some code that uses setfocus to move the user to the first field in a subform).

       

      In most languages, there are ways to refer to child controls via an indexer or an items/children array. i.e. Subform.items[0].rawValue.

       

      I know that this would pose some issues, but I think I could sort it out, if only I knew where to start. Is there some way to reference a child control without it's name?

       

      Thanks for your help!

       

      - Scott

        • 1. Re: How do I use javascript or formcalc to reference child controls (not by name)
          BR001 Community Member

          Hi Scott,

           

          The subform has a nodes collection you can loop though, as you suspected.  If might show up more than you want but you can test the className to see if it is a field and then ui.oneOfChild.className to work out what type of field. So;

           

          for (var i = 0; i < Subform1.nodes.length; i++)

          {

              var n = Subform1.nodes.item(i);

              console.println(n.className + " " + n.name + " " + n.ui.oneOfChild.className);

          }

           

          Hope this helps.

           

          Bruce