6 Replies Latest reply on Mar 11, 2015 12:53 PM by Zantcor

    Can anyone help with with this dialog?

    Eiranix Level 1

      I have put together a dialog but I'm not sure how to get it working properly...

       

      1) I want the checkbox to disable the last 3 fields and make their value be the same as the first field.

      2) have the variables from the fields and selected radio to come through into the alert

       

       

      #target illustrator
      
      //window
      var win = new Window('dialog', "My Dialog");
      this.windowRef = win;
      
      //panels
      win.fieldpanel = win.add("panel", undefined, "");
      win.radiopanel = win.add("panel", undefined, "");
      
      //panel orientation
      win.fieldpanel.orientation='row';
      win.radiopanel.orientation='row';
      
      //fieldpanel
      win.fieldpanel.panel1 = win.fieldpanel.add('panel', undefined, "Left");
      win.fieldpanel.panel2 = win.fieldpanel.add('panel', undefined, "Right");
      win.fieldpanel.panel3 = win.fieldpanel.add('panel', undefined, "Top");
      win.fieldpanel.panel4 = win.fieldpanel.add('panel', undefined, "Bottom");
      
      win.fieldpanel.panel1.left_input = win.fieldpanel.panel1.add('edittext', undefined, "0");
      win.fieldpanel.panel2.right_input = win.fieldpanel.panel2.add('edittext', undefined, "0");
      win.fieldpanel.panel3.top_input = win.fieldpanel.panel3.add('edittext', undefined, "0");
      win.fieldpanel.panel4.bottom_input = win.fieldpanel.panel4.add('edittext', undefined, "0");
      
      win.fieldpanel.panel1.left_input.characters = 5;
      win.fieldpanel.panel2.right_input.characters = 5;
      win.fieldpanel.panel3.top_input.characters = 5;
      win.fieldpanel.panel4.bottom_input.characters = 5;
      
      win.fieldpanel.check1 = win.fieldpanel.add('checkbox', undefined, "Equal"); 
      
      //radiopanel
      win.radiopanel.radio1 = win.radiopanel.add('radiobutton',undefined, "Option 1"); 
      win.radiopanel.radio2 = win.radiopanel.add('radiobutton',undefined, "Option 2"); 
      win.radiopanel.radio3 = win.radiopanel.add('radiobutton',undefined, "Option 3"); 
      
      //select first radio button
      win.radiopanel.radio1.value = true;
      
      //ok button
      win.okbutton = win.add('button',undefined, "Ok"); 
      
      //disable fields with checkbox and equal values
      win.fieldpanel.check1.onCLick = function() {
        if(win.fieldpanel.check1.value){
          var leftvalue = win.fieldpanel.left_input.text;
          win.fieldpanel.right_input.text = left;
          win.fieldpanel.top_input.text = left;
          win.fieldpanel.bottom_input.text = left;
      
          win.fieldpanel.right_input.enabled = false;
          win.fieldpanel.top_input.enabled = false;
          win.fieldpanel.bottom_input.enabled = false;
        } else {
          win.fieldpanel.right_input.enabled = true;
          win.fieldpanel.top_input.enabled = true;
          win.fieldpanel.bottom_input.enabled = true;
        }
      };
      
      //event listener for radio buttons
      win.radiopanel.radio1.onClick = win.radiopanel.radio2.onClick = win.radiopanel.radio3.onClick = function () {
        var selected = "";
        if(win.radiopanel.radio1.value) {
          selected = 1;
        }
        else if(win.radiopanel.radio2.value) {
          selected = 2;
        }
        else if(win.radiopanel.radio3.value) {
          selected = 3;
        }
      };
      
      //event listener for ok button
      win.okbutton.onClick = function(){
        var left = win.fieldpanel.left_input.text;
        var right = win.fieldpanel.right_input.text;
        var top = win.fieldpanel.top_input.text;
        var bottom = win.fieldpanel.bottom_input.text;
        if (selected = 1) {var option = "Option 1"};
        if (selected = 2) {var option = "Option 2"};
        if (selected = 3) {var option = "Option 3"};
      
        win.close();
        alert(left+", "+right+", "+top+", "+bottom+", "+option);
      };
      
      win.show()
      
        • 1. Re: Can anyone help with with this dialog?
          CarlosCanto Adobe Community Professional & MVP

          you have a number of syntax errors, other than that it should work

           

          case sentive

           

          //disable fields with checkbox and equal values
          win.fieldpanel.check1.onCLick = function() { // misspelled

           

           

          in lots of lines like the below in pink you are missing panel1, panel2, panel3, panel4

           

              var leftvalue = win.fieldpanel.left_input.text; // missing panel1

           

           

          left is undefined, it should be leftvalue

           

              win.fieldpanel.right_input.text = left; // should be leftvalue

          • 2. Re: Can anyone help with with this dialog?
            Eiranix Level 1

            Edit- was being blind... Work great now thanks so much!

             

            Btw is it possible to have the three disabled fields mirror the first field as you type in it?

            • 3. Re: Can anyone help with with this dialog?
              Eiranix Level 1

              Ok I've just realised that the radio buttons always give "Option 3" in the alert, no matter which was selected... Any ideas?

               

              //event listener for radio buttons
              win.radiopanel.radio1.onClick = win.radiopanel.radio2.onClick = win.radiopanel.radio3.onClick = function () {
                var selected = "";
                if(win.radiopanel.radio1.value) {
                  selected = 1;
                }
                else if(win.radiopanel.radio2.value) {
                  selected = 2;
                }
                else if(win.radiopanel.radio3.value) {
                  selected = 3;
                }
              };
              
              //event listener for ok button
              win.okbutton.onClick = function(){
                if (selected = 1) {var option = "Option 1"};
                if (selected = 2) {var option = "Option 2"};
                if (selected = 3) {var option = "Option 3"};
              
                win.close();
                alert(option);
              };
              

               

              Edit: I moved the event listener for radio buttons function to inside the ok button function which solved the problem.

              • 4. Re: Can anyone help with with this dialog?
                CarlosCanto Adobe Community Professional & MVP

                you're welcome,

                 

                Btw is it possible to have the three disabled fields mirror the first field as you type in it?

                yes, use the onChanging event on the first field.

                • 5. Re: Can anyone help with with this dialog?
                  Eiranix Level 1

                  Perfect, thanks again.

                  • 6. Re: Can anyone help with with this dialog?
                    Zantcor Level 1

                    I know this is old but I saw this as I was scrolling through the forums;

                     

                    You have = instead of == in the if statement it should read like this;

                     

                    //event listener for ok button  
                    win.okbutton.onClick = function(){  
                      if (selected == 1) {var option = "Option 1"};  
                      if (selected == 2) {var option = "Option 2"};  
                      if (selected == 3) {var option = "Option 3"}; 
                    
                    

                     

                    as it was checking it was making the var selected = 3 as it was the last line you use one = to make it into something == to do a soft check so (a == A) is true but you use === to do a hard check so (a === A) would be false.

                     

                    Hope that helps if you haven't figured it out already.