5 Replies Latest reply on Jun 22, 2012 11:34 AM by dgolberg

    Dynamically Create (and reference) Dialog Window Groups

    dgolberg Level 1

      I'm trying to setup a dialog window that can be easily added to via a CSV file.  The only problem I've run into is; I'm not quite sure how to create the groups dynamically.  Basically, the script setups up a bunch of texture features and then gives the option to save and/or strip that feature.  Below is the basic idea of what I'm trying to do, but the groups are not able to be created in the way that they are shown:

       

      featArray = [];
      featArray[0] = new Array("Feature Display Name","feature sub-group",'texture',"feature action",'feature type');
      featArray[1] = new Array("Feature2 Display Name","feature2 sub-group",'texture',"feature2 action",'feature2 type'); //etc.
      
      for(var z in featArray) {
          if(featArray[z][2] == 'texture') {
              w.p1.sp1.add('statictext',undefined,featArray[z][0]);
              w.p1.sp1.g[z] = w.p1.sp1.add('group');
              w.p1.sp1.g[z].orientation = 'row';
              w.p1.sp1.g[z].add('checkbox',undefined,'Save');
              w.p1.sp1.g[z].add('checkbox',undefined,'Strip');
              w.p1.sp1.g[z].children[0].id = featArray[z][0].toLowerCase() + "-save";
              w.p1.sp1.g[z].children[1].id = featArray[z][0].toLowerCase() + "-strip";
          }
      }
      

       

      If you change the g[z] to g1, it will create each field correctly (visually), but there is no way to properly reference the check boxes to see which are checked.  Any ideas how, or even if, it is possible to dynamically create a different group for each line of the featArray?  And if so, how to then reference the check boxes in those groups later on?  Thanks in advance for any help!

        • 1. Re: Dynamically Create (and reference) Dialog Window Groups
          Paul Riggott Level 6

          You need to store the locations in an array IE:-

           

           

          featArray = [];
          featArray[0] = new Array("Feature Display Name","feature sub-group",'texture','feature group','feature type');
          featArray[1] = new Array("Feature Display Name2","feature sub-group2",'texture','feature group2','feature type2'); //etc.
          var w = new Window('dialog','test');
          w.p1= w.add("panel", undefined, undefined, {borderStyle:"black"}); 
          var x = new Array();
          var count =0;
          for(var z in featArray) {
              if(featArray[z][2] == 'texture') {
                  w.p1.add('statictext',undefined,featArray[z][0]);
          w.p1.g = w.p1.add('group');
          w.p1.g.orientation = 'row';
          x[count] = w.p1.g.add('checkbox',undefined,'Save');
          count++;
          x[count] = w.p1.g.add('checkbox',undefined,'Strip');
          count++
              }
          }
          w.test = w.add('button',undefined,'Press to Test');
          w.add('button',undefined,'Cancel');
          w.test.onClick=function(){
          for(var w =0;w<x.length;w++){
              alert("Checkbox " + w + " value = " +x[w].value);
              }
          }
          w.center();
          w.show();
          
          
          • 2. Re: Dynamically Create (and reference) Dialog Window Groups
            dgolberg Level 1

            Wow, such a simple solution.  I guess this is a case of me making things out to be harder than they really are, lol.  Thanks a ton Paul!

            • 3. Re: Dynamically Create (and reference) Dialog Window Groups
              dgolberg Level 1

              One more question.  How would I add an "onClick" function or event listener to these arrayed checkboxes?  I want the action of checking these boxes to run a check on the document to confirm that the feature being checked for saving or stripping exists in the document.

              • 4. Re: Dynamically Create (and reference) Dialog Window Groups
                Paul Riggott Level 6

                You just use the array ie:

                 

                 

                featArray = [];
                featArray[0] = new Array("Feature Display Name","feature sub-group",'texture','feature group','feature type');
                featArray[1] = new Array("Feature Display Name2","feature sub-group2",'texture','feature group2','feature type2'); //etc.
                var w = new Window('dialog','test');
                w.p1= w.add("panel", undefined, undefined, {borderStyle:"black"}); 
                var x = new Array();
                var count =0;
                for(var z in featArray) {
                    if(featArray[z][2] == 'texture') {
                        w.p1.add('statictext',undefined,featArray[z][0]);
                w.p1.g = w.p1.add('group');
                w.p1.g.orientation = 'row';
                x[count] = w.p1.g.add('checkbox',undefined,'Save');
                count++;
                x[count] = w.p1.g.add('checkbox',undefined,'Strip');
                count++
                    }
                }
                x[0].onClick=function(){
                    alert("Checkbox 0 clicked");
                    }
                x[1].onClick=function(){
                    alert("Checkbox 1 clicked");
                    }
                x[2].onClick=function(){
                    alert("Checkbox 2 clicked");
                    }
                x[3].onClick=function(){
                    alert("Checkbox 3 clicked");
                    }
                w.test = w.add('button',undefined,'Press to Test');
                w.add('button',undefined,'Cancel');
                w.test.onClick=function(){
                for(var w =0;w<x.length;w++){
                    alert("Checkbox " + w + " value = " +x[w].value);
                    }
                }
                w.center();
                w.show();
                
                
                1 person found this helpful
                • 5. Re: Dynamically Create (and reference) Dialog Window Groups
                  dgolberg Level 1

                  Interesting.  This has opened up a LOT more ideas for making my GUIs more dynamic.  Thanks a ton Paul!