Skip to main content
Inspiring
May 7, 2016
Answered

Apply Button?

  • May 7, 2016
  • 2 replies
  • 1277 views

I've been messing with this for way too long.  How do you make an apply button work on a scrtip?  below is what i have and it shows up but does not work.    

w.buttons  = w.add ('group {alignment: "right"}');

w.buttons.add  ('button {text: "Apply"}');// this one shows up but does not work

w.add ("button", undefined, "Apply");// same with this one.

w.buttons.add  ('button {text: "OK"}');

w.buttons.add  ('button {text: "Cancel"}');

The Ok and Cancel buttons work fine.  I cannot make any of the APPLY buttons just apply the changes from my check boxes i have. 

Thanks in advance.

This topic has been closed for replies.
Correct answer Peter Kahrel

The Apply button would activate the RunCH1, 2 and 3 on line 19-21.  The search strings to activate start on 156

    

    var myResult;

    var w =new Window ('dialog {text: "Running Changes", orientation: "column", alignChildren:["fill","fill"],   properties:   {closeButton:   false}}');

    

    

       w.main =w.add ('group {preferredSize: [600, 600], alignChildren: ["left","fill"]}');

        w.stubs  = w.main.add ('listbox', undefined, ['Changes',  'Check For Changes', 'Example']);

        w.stubs.preferredSize.width  = 120;  w.tabGroup  = w.main.add ('group {alignment: ["Fill","Fill"], orientation: "stack"}');

            w.tabs  =[];

                w.tabs[0]= w.tabGroup.add ('group');

                w.tabs[0].add('statictext {text: ""}');

            w.tabs  =[];

                w.tabs[0]= w.tabGroup.add ('group');

                w.tabs[0].add('statictext {text: "Select a change to make"}');

            w.tabs[0].add ('panel');

    

        var RunCH1= w.tabs[0].add ('checkbox {text: "Find and Replace"}');

        var RunCH2= w.tabs[0].add ('checkbox {text: "GHS Running Changes"}');

        var RunCH3= w.tabs[0].add ('checkbox {text: "Non-GHS Running Changes"}');      

        

                

                 var Pan1=w.tabs[0].add ('panel {text: "Find and Replace", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","Center"]}');

             

                    Pan1.add('statictext {text: "Double Space   -   Single Space"}');

                    Pan1.add('statictext {text: "Space :    -   :"}');

                    Pan1.add('statictext {text: "Space .    -   ."}');

                    Pan1.add('statictext {text: "<CR>   -   Return"}');

                    Pan1.add('statictext {text: "Double Return  -   Return"}');

                      

               

                 var Pan1=w.tabs[0].add ('panel {text: "GHS Running Changes", preferredSize: [-1, 150],orientation: "column",alignChildren: ["left","Center`"]}');

              

                    Pan1.add('statictext {text: "B1.   Enter Here1"}');

                    Pan1.add('statictext {text: "B2.   Enter Here2"}');

                    Pan1.add('statictext {text: "B3.   Enter Here3"}');

                    Pan1.add('statictext {text: "B4.   Enter Here4"}');

            

            

             

                var Pan1=w.tabs[0].add ('panel {text: "Non-GHS Running Changes", preferredSize: [-1, 150],orientation: "column",alignChildren: ["left","Center`"]}');

              

                    Pan1.add('statictext {text: "B1.   Enter Here5"}');

                    Pan1.add('statictext {text: "B2.   Enter Here6"}');

                    Pan1.add('statictext {text: "B3.   Enter Here7"}');

                    Pan1.add('statictext {text: "B4.   Enter Here8"}');

    

                 var Pan1=w.tabs[0].add ('panel {text: "Contact Infromation", preferredSize: [-1, 62],orientation: "column",alignChildren: ["left","Center`"]}');

              

                    Pan1.add('statictext {text: "*email Address here*"}');

                  

            

    

        with(w.tabs[0])

        {

        with(add ('group {alignment: "left"}'))

        {

                       add ('button {text: "Reset all warning dialogs"}');

        }

        }

            w.tabs[1]= w.tabGroup.add ('group');

            w.tabs[1].add ('statictext {text: "Changes that WILL need checked"}');

            w.tabs[1].add ('panel {preferredSize: [-1, -10]}');

            var Pan1=w.tabs[1].add ('panel {text: "GHS", preferredSize: [-1, 250],orientation: "column",alignChildren: ["left","Center`"]}');

              

                    Pan1.add('statictext {text: "B1.   Here"}');

                    Pan1.add('statictext {text: "B2.   Here"}');

                    Pan1.add('statictext {text: "B3.   Here"}');

                    Pan1.add('statictext {text: "B4.   Here"}');

                    Pan1.add('statictext {text: "B5.   Here"}');

                    Pan1.add('statictext {text: "G1.   Here"}');

                    Pan1.add('statictext {text: "G2.   Here"}');

                        

            w.tabs[1].add ('panel {text: "Non-GHS", preferredSize: [-1, 100]}');

            w.tabs[2]= w.tabGroup.add ('group');

            w.tabs[2].add ('statictext {text: "Example Of running Changes"}');

            w.tabs[2].add ('panel');

            w.tabs[2].add ('statictext {text: "", preferredSize: [-1, 20]}');

         

      // How can i make PreV1 activate the below Radio buttons?  Maybe gray out the Buttons when not the Check box is not checked.

    

            var PreV1= w.tabs[2].add ('checkbox {text: "To Preview Changes"}');

            var Pan1=w.tabs[2].add ('panel {text: "", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","top"]}');

         

      // Is there a way to make each radio button display a Different Pictrue?       

    

                    Pan1.add('radioButton {text: "B1.   Enter Here1"}');

                    Pan1.add('radioButton {text: "B2.   Enter Here2"}');

                    Pan1.add('radioButton {text: "B3.   Enter Here3"}');

                    Pan1.add('radioButton {text: "B4.   Enter Here4"}');

                    Pan1.add('radioButton {text: "B1.   Enter Here5"}');

                    Pan1.add('radioButton {text: "B2.   Enter Here6"}');

                    Pan1.add('radioButton {text: "B3.   Enter Here7"}');

                    Pan1.add('radioButton {text: "B4.   Enter Here8"}');

       /*

    

               Image.prototype.onDraw =function()

                {

                if(!this.image )return;

                var WH =this.size,wh   =this.image.size,k   = Math.min(WH[0]/wh[0], WH[1]/wh[1]), xy;

                  wh   =[k*wh[0],k*wh[1]];

                  xy   =[(WH[0]-wh[0])/2, (WH[1]-wh[1])/2 ];

                this.graphics.drawImage(this.image,xy[0],xy[1],wh[0],wh[1]);

                   WH   = wh = xy =null;

                }

               flower=w.tabs[2].add ("image", undefined, File ("~/\Desktop/\xxx.jpg"));

               flower.size =[300,300];

          */  

    

   // I cannot seem to get this Apply button to work

  

                w.buttons  = w.add ('group {alignment: "right"}');

                applyButton = w.buttons.add ('button {text: "Apply"}');

                applyButton.onClick = function () {

                   applySelection    

                        }

                w.buttons.add  ('button {text: "OK"}');

                w.buttons.add  ('button {text: "Cancel"}');

       

        for(

        var i = 0;

         i < w.tabs.length;

         i++){

        w.tabs.orientation ='column';

        w.tabs.alignChildren ='fill';

        w.tabs.alignment =['fill','fill'];

        w.tabs.visible =false;

        }

        w.stubs.onChange  = showTab;

        function

         showTab ()

        {

        if(w.stubs.selection !==null){for(var i = w.tabs.length-1; i >= 0;

         i--)

         {   

             w.tabs.visible =false;

        }

                 w.tabs[w.stubs.selection.index].visible =true;

        }

        }

          w.onShow  =function()

        {

        w.stubs.selection  = 1;

        showTab;

        }

    

    

    myResult = w.show();

    

    // How do i make each CHECK BOX RunCH1/2/3 Only work when they are selected?  I cannot figure out how to make 2&3 Work.

        if(myResult == 1 && (RunCH1.value==true || RunCH2.value==true || RunCH3.value==true) ){ 

            alert("Find and Replace Items Have been made.!")

                Replace_TXT(" <CR> ", "^p");

                Replace_TXT(" <CR>", "^p");

                Replace_TXT("  ", " ");

                Replace_TXT(" :", ":");

                Replace_TXT(" .", ".");

                Replace_TXT("^p^p", "^p");

               

              

             

            if(myResult == 2 && (RunCH2.value==true ) );

          

                Replace_TXT ("test", "asdfasdfasdfadsfasdfasdfasdfadfasdfasdf");

                   

         { 

                    alert ("GHS Changes Made") 

         };

    

            if(myResult == 3 && (RunCH3.value==true) ){ 

                Replace_TXT("and", "TEST");

          } 

                   alert ("NON-GHS Changes Made") 

          };

            w.close(true);    

   

    

    function Replace_TXT(input, output) 

    { 

    app.findChangeTextOptions.caseSensitive = true; 

    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 

    app.findTextPreferences.findWhat = input; 

    app.changeTextPreferences.changeTo = output; 

    app.activeDocument.changeText(); 

    }


> The Apply button would activate the RunCH1, 2 and 3

I guess you mean that the user ticks any of the three checkboxes and that when they click Apply, the script executes the actions associated with the ticked checkboxes. Correct? You need a palette-type window for that, not a dialog.

applyButton.onClick = function () {

  if (RunCH1.value==true) {

    // . . .

  }

  if (RunCH2.value==true) {

    // . . .

  }

  if (RunCH3.value==true) {

    // . . .

  }

}

If you do want to use a dialog you need to create an object with the window's options and return that object. Your script then processes that object.

Peter

2 replies

Peter Kahrel
Community Expert
Community Expert
May 8, 2016

Buttons with the text OK and Cancel work by default in response to the Return and Esc keys. For any other button you have to specify what should happen when they're clicked:

applyButton = w.buttons.add  ('button {text: "Apply"}');

. . .

applyButton.onClick = function () {

  // do something

}

Peter

cbishop01Author
Inspiring
May 8, 2016

what would the function to apply be?  I'm a super novice at programming.  also the ... gives me an error.  I'm wanting this apply button to activate the Checkboxes i have.   if you need the rest of the code here to help you out let me know and i'll put whatever you need on here.  thank you

Peter Kahrel
Community Expert
Community Expert
May 8, 2016

> what would the function to apply be?

Whatever you want it to be/do.

> the ... gives me an error.

The ellipsis was just to indicate 'more code', used in the sense of points of omission -- not points of suspension, as it were. You shouldn't use it like that in a script. . .

Peter Spier
Community Expert
Community Expert
May 7, 2016

I've moved this into the scripting forum...