10 Replies Latest reply on Oct 1, 2014 5:19 AM by virender_CTS

    radio button created by script. Need help on cancel button.

    virender_CTS Level 1

      hi,

       

      after running this script, when i select german, french or italy button and clicked on cancel button, then window should closed but it shows respective alert e.g. "u clicked German"

       

      thanks

      Virender

       

       

      var win = new Window ("dialog");

      win.alignChildren = "left";

       

      win.German = win.add ("radiobutton", undefined, "German");

      win.French = win.add ("radiobutton", undefined, "French");

      win.Italy = win.add ("radiobutton", undefined, "Italy");

       

      win.cancelBtn = win.add("button", undefined, "cancel"); 

      win.quitBtn = win.add("button", undefined, "Ok"); 

      win.defaultElement = win.quitBtn; 

      win.cancelElement = win.cancelBtn; 

       

      //win.German.value = true; 

       

      win.quitBtn.onClick = function() { 

          end = 1; 

          win.close(); 

          }

       

      win.cancelBtn.onClick = function() { 

          end = 1; 

          win.close(); 

          }

       

      win.show(); 

       

      if (win.German.value == true)

      {

          alert ("u clicked German")

          };

       

      if (win.French.value == true)

      {

          alert ("u clicked French")

          };

       

      if (win.Italy.value == true)

      {

          alert ("u clicked Italy")

          };

        • 1. Re: radio button created by script. Need help on cancel button.
          Laubender Adobe Community Professional & MVP

          @virender_CTS – just tested your code with my InDesign CS6 (German) on Mac OSX 10.7.5. All is working as expected (I added a #targetengine statement at the beginning): I checked the radio button for "German" and pressed "Ok", that will close the dialog and an alert will pop up "u clicked German" . Respectively the same for the other options. "Cancel" will cancel the dialog.

           

          If I check the radio button for "German" and then press "Cancel" the alert will pop up and the dialog will close (as expected from looking into your code).

           

          What would you expect?
          What behaviour do you see?

           

          What version of InDesign are you using?

           

          If you want a new behaviour like that:

          User clicked "German" and then "Cancel", you have to add this case to your code.

          Something like this:

           

          if (win.German.value == true && end == 1)
          {
              //Something that stops the script from running code below.
              //For example this:
              exit();
              };
          
          if (win.German.value == true)
          {
              alert ("u clicked German")
              };
          

           

          Uwe

          • 2. Re: radio button created by script. Need help on cancel button.
            virender_CTS Level 1

            Hi Uwe,

            Vielen Dank for the reply. I am at home, just using extendsciprt CS6 editor English on PC. I don't have mac at home

             

            I want if a user select any button out of three and click on cancel button so the respective code should not execute. For me now at PC, "exit" code is not working.

             

            Virender

            • 3. Re: radio button created by script. Need help on cancel button.
              TᴀW Adobe Community Professional & MVP

              Pass a value to the show() command, and check the result. E.g.:

               

              myResult = myWindow.show();

               

              if (myResult == -1){

              exit();

              }

               

              ...

              myWindow.close(-1);

              • 4. Re: radio button created by script. Need help on cancel button.
                virender_CTS Level 1

                hi Ariel,

                thanks for the reply but i am not very good on this part of scripting UI.

                Any code suggestion altering my code will be very helpful.

                 

                Virender

                • 5. Re: radio button created by script. Need help on cancel button.
                  TᴀW Adobe Community Professional & MVP

                  Let me give you a working example:

                   

                  w = new Window("dialog");

                  w.add("button", undefined, "Cancel");

                  w.add("button", undefined, "OK");

                  r = w.show();

                  alert(r);

                   

                   

                  You'll notice that for buttons labeled specifically "Cancel" and "OK"

                  you don't actually need to provide a return value yourself. When the

                  user clicks Cancel, the value of 2 is returned. For OK, 1.

                   

                  So all your script has to do is check the return value for show(), and

                  act accordingly. If you want to exit the script, check if the return

                  value is 2, and exit().

                   

                  I'm sorry that I don't have time right now to alter your script. It's

                  much quicker to write this explanation. Perhaps I'll get a chance later.

                  • 6. Re: radio button created by script. Need help on cancel button.
                    virender_CTS Level 1

                    Hi Ariel,

                     

                    I understood your point, I am trying now.

                     

                    Thanks

                    Virender

                    • 7. Re: radio button created by script. Need help on cancel button.
                      virender_CTS Level 1

                      hi Ariel, hi Laubender, hi all,

                       

                      I am not able to get the desired results which is on clicking cancel button, script should not show any alert.

                       

                      thanks

                      virender

                      • 8. Re: Re: radio button created by script. Need help on cancel button.
                        Sajeev Sridharan Level 4

                        Try this, this may help you

                         

                        var win = new Window ("dialog");
                        win.alignChildren = "left";
                        win.German = win.add ("radiobutton", undefined, "German");
                        win.French = win.add ("radiobutton", undefined, "French");
                        win.Italy = win.add ("radiobutton", undefined, "Italy");
                        
                        win.cancelBtn = win.add("button", undefined, "cancel"); 
                        win.quitBtn = win.add("button", undefined, "Ok"); 
                        win.defaultElement = win.quitBtn; 
                        win.cancelElement = win.cancelBtn; 
                        
                        win.quitBtn.onClick = function() { 
                            end = 1; 
                            win.close(); 
                            }
                        
                        win.cancelBtn.onClick = function() { 
                            end = 0; 
                            win.close(); 
                            }
                        
                        win.show(); 
                        
                        if (win.German.value == true && end==1)
                        {
                            alert ("u clicked German")
                            };
                        
                        if (win.French.value == true && end==1)
                        {
                            alert ("u clicked French")
                            };
                        
                        if (win.Italy.value == true && end==1)
                        {
                            alert ("u clicked Italy")
                            };
                        

                         

                         

                        Vandy

                        • 9. Re: Re: radio button created by script. Need help on cancel button.
                          TᴀW Adobe Community Professional & MVP
                          var win = new Window ("dialog");
                          win.alignChildren = "left";
                          win.German = win.add ("radiobutton", undefined, "German");
                          win.French = win.add ("radiobutton", undefined, "French");
                          win.Italy = win.add ("radiobutton", undefined, "Italy");
                          win.cancelBtn = win.add("button", undefined, "Cancel");  
                          win.quitBtn = win.add("button", undefined, "OK");  
                          win.defaultElement = win.quitBtn;  
                          win.cancelElement = win.cancelBtn;  
                          if (win.show() == 1){
                           if (win.German.value == true)
                           {
                            alert ("u clicked German")
                           };
                           if (win.French.value == true)
                           {
                            alert ("u clicked French")
                           };
                           if (win.Italy.value == true)
                           {
                            alert ("u clicked Italy")
                           };
                          }
                          
                          • 10. Re: radio button created by script. Need help on cancel button.
                            virender_CTS Level 1

                            hi Ariel,

                            thank u veryyyyyyyyyyy much.

                             

                            Regards

                            Virender