9 Replies Latest reply on Feb 9, 2015 8:42 PM by creativejoan0425

    UI dialog error ( Cannot handle request because a modal dialog or alert is active)

    creativejoan0425 Level 1

      I have a dialog which only can run when u select cell, after showing the dialog, I click check1 it will popup another dialog and close the previous dialog, but when I press "enter", I will alert "Cannot handle request because a modal dialog or alert is active", and cannot run the dialog 2 action


      // start myGet Columns Info ---------------------------------------------          

          //now col width

          var mySelColWid = app.selection[0].cells[0].width;

      // end of myGet Columns Info ---------------------------------------------  

      myDisplayDialog2_new();

      function myDisplayDialog2_new(){

       

      //w1 ----------

          var w = new Window("dialog", "Adjust Col._v1.0");

                w.alignChildren = "left";

          var g = w.add ("group");

          var check1 = g.add ("checkbox", undefined, "Figure Col.?");

                 check1.value = true;

          var g2 = w.add ("group");

          var panel = g2.add("panel");

                 panel.orientation = "column";

          var my1row = panel.add("group");

                my1row.orientation = "row";

                my1row.alignment = "left";

                my1row.add ("statictext", undefined, "Col. Width:");

                var myText = my1row.add ("edittext", undefined, mySelColWid);

                      myText.characters = 7;

                      myText.active = true;

          var my5row = panel.add("group");

                my5row.orientation = "row";

                my5row.alignment = "left";

                my5row.add ("button", undefined, "Ok", {name: "ok"});

                my5row.add ("button", undefined, "Cancel", {name: "cancel"});

      //w1 ----------

      check1.addEventListener ("click", function ()

      {

          w.close();

          myDisplayDialog3_new();

          }

      );

      var myWindow1 = w.show();

           if( myWindow1 ==true){

                  app.selection[0].cells.everyItem().width = 100;

          }

      }

      function myDisplayDialog3_new(){

      //w2 ----------

      var w2 = new Window("dialog", "Adjust Col._v1.0");

              w2.alignChildren = "left";

          

      var gA = w2.add ("group");

      var check1a = gA.add ("checkbox", undefined, "Text Col.?");

             check1a.value = false;

      var gB = w2.add ("group");

      var panelA = gB.add("panel");

             panelA.orientation = "column";

      var my1row = panelA.add("group");

            my1row.orientation = "row";

            my1row.alignment = "left";

            my1row.add ("statictext", undefined, "Test Width:");

            var myText_w2 = my1row.add ("edittext", undefined, mySelColWid);

                  myText_w2.characters = 7;

                  myText_w2.active = true;

      var my7row = panelA.add("group");

            my7row.orientation = "row";

            my7row.alignment = "left";

               my7row.add ("button", undefined, "Ok", {name: "yo"});

              my7row.add ("button", undefined, "Cancel", {name: "no"});

      //w2 ----------

      check1a.addEventListener ("click", function ()

      {

          w2.close();

          myDisplayDialog2_new();

          }

      );

          var myWindow2 = w2.show();

          if (myWindow2 == true){

              try{app.selection[0].cells.everyItem().width = 50;

                  }

              catch(e){alert(e);}

          }

      }

        • 1. Re: UI dialog error ( Cannot handle request because a modal dialog or alert is active)
          Peter Spier Most Valuable Participant (Moderator)

          This appears to be a scripting question, so I've moved it to the scripting forum.

          • 3. Re: UI dialog error ( Cannot handle request because a modal dialog or alert is active)
            Loic.Aigon Adobe Community Professional

            Hi,

             

            You want to check if your dialog returns 1 but actually returns nothing => w.close();

             

            try w.close(1);

             

            Loic

            http://ww.ozalto.com

            • 5. Re: UI dialog error ( Cannot handle request because a modal dialog or alert is active)
              Loic.Aigon Adobe Community Professional

              Hi,

              I have this feeling you are overcomplicating stuff here but maybe I just didn't got the idea. If your intention is to "redraw" the UI when user picks one choice or the other, the same can be achieved more simply

              Capture d’écran 2015-02-06 à 22.05.51.png

              function main(defaultWidth) {
                var w = new Window ("dialog", "Adjust Col._v1.0" );
                var tp = w.add('panel', undefined, "Choose target to apply width…" );
                var dd = tp.add('dropdownlist',undefined, ["Text", "Col"]);
                var vp = w.add('panel', undefined, "Set width value…" );
                var ti = vp.add('edittext', undefined, defaultWidth );
              
                var btnGp = w.add('group');
                var koBtn = btnGp.add('button', undefined, "Cancel");
                var okBtn = btnGp.add('button', undefined, "OK");
              
                btnGp.orientation = "row";
                btnGp.alignment = "fill";
                btnGp.alignChildren = ["fill","right"];
              
                tp.alignment = "fill";
                dd.alignment = "fill";
              
                vp.alignment = "fill";
                ti.alignment = "fill";
              
                dd.selection = 0;
              
              
                koBtn.onClick = function() { w.close(0); }
              
                okBtn.onClick = function() { w.close(1); }
              
                if ( w.show() == 1 ) {
                alert( "you want to apply "+ti.text+" on "+dd.selection.text );
                }
              }
              
              
              
              
              main(500);
              

               

               

              HTH

               

              Loic

              http://www.ozalto.com

              • 6. Re: UI dialog error ( Cannot handle request because a modal dialog or alert is active)
                creativejoan0425 Level 1

                In fact I want to have 2 window, cause I didt jus have one option for the text and col

                for example text I may have 3 different button and col hv 5 different button, so I want to switch different dialog

                • 8. Re: UI dialog error ( Cannot handle request because a modal dialog or alert is active)
                  Loic.Aigon Adobe Community Professional

                  Hi,

                   

                  I would choose to stay in the same view. But it's easy to redraw some parts on the UI given user interaction. In this example, depending on what radiobutton user selects youc an hide/display differents UI components.

                   

                  function main(defaultWidth) {  
                  
                    var w = new Window ("dialog", "Adjust Col._v1.0" );  
                    var rbGp = w.add('group');
                    var rb1 = rbGp.add('radiobutton',undefined, "X");
                    var rb2 = rbGp.add('radiobutton',undefined, "Y");
                    var rb3 = rbGp.add('radiobutton',undefined, "Z");
                    
                    rb1._id = "rb1";
                    rb2._id = "rb2";
                    rb3._id = "rb3";
                    
                    rb1.value = true;
                    rbGp.alignment = "fill";  
                    var _sel = rb1.text;
                    
                    var optGp = w.add('group');
                    optGp.orientation = 'stack';
                    optGp.alignment = "fill";
                    optGp.alignChildren = ["left", "fill"];
                  
                    var st1 = optGp.add('statictext',undefined, 'Set X…');
                    var st2 = optGp.add('statictext',undefined, 'Set Y…');
                    var st3 = optGp.add('statictext',undefined, 'Set Z…');
                    st2.visible = st3.visible = false;
                    
                    var btnGp = w.add('group');  
                    var koBtn = btnGp.add('button', undefined, "Cancel");  
                    var okBtn = btnGp.add('button', undefined, "OK");  
                    
                    btnGp.orientation = "row";  
                    btnGp.alignment = "fill";  
                    btnGp.alignChildren = ["fill","right"];  
                    
                    
                    var f =  function(e){ 
                     var id = e.target._id;
                     
                     st1.visible = id=="rb1";
                     st2.visible = id=="rb2";
                     st3.visible = id=="rb3";
                     
                     _sel = e.target.text;
                    };
                    
                    rbGp.addEventListener ( 'click', f, true);
                    
                    koBtn.onClick = function() { w.close(0); }  
                    
                    okBtn.onClick = function() { w.close(1); }  
                    
                    if ( w.show() == 1 ) {  
                    alert("You want to edit "+_sel+" property" );
                    }  
                  }  
                    
                    
                    
                    
                  main(500); 
                  

                   

                  HTH

                   

                  Loic

                  http://www.ozalto.com

                  • 9. Re: UI dialog error ( Cannot handle request because a modal dialog or alert is active)
                    creativejoan0425 Level 1

                    How about this one?

                     

                     

                        //defined the Text Frame Width

                        var myDocWidth = app.activeDocument.documentPreferences.pageWidth

                        var myDocActuralWidth = Math.round (myDocWidth);

                        var myLeftPageMargin = app.activeWindow.activePage.marginPreferences.left;

                        var myRightPageMargin = app.activeWindow.activePage.marginPreferences.right;

                        var myTextFrameWidth = myDocActuralWidth - myLeftPageMargin - myRightPageMargin;

                        //end of defined the Text Frame Width

                    // start myGet Columns Info ---------------------------------------------          

                        //now col width

                        var mySelColWid = app.selection[0].cells[0].width;

                        //now col left indent

                        var mySelColLIndnet = app.selection[0].cells[0].leftInset;

                        //now col rigt indent

                        var mySelColRIndnet = app.selection[0].cells[0].rightInset;

                        //now table indent

                        var mySelTabIndnet = app.selection[0].parent.storyOffset.leftIndent;

                       // now tab position and have leader or not

                        var mySelColNumberTabStops = [];

                        var mySelTextContents = [];

                        var mySelColTextTabStops = [];

                        var mySelTableColumns = app.selection[0].columns[0].cells.everyItem().texts.everyItem().getElements();

                        for (var a=0; mySelTableColumns.length >a; a++){

                            mySelColNumberTabStops.push(mySelTableColumns[a].tabStops.everyItem().position);

                            mySelTextContents.push(mySelTableColumns[a].contents);

                            mySelColTextTabStops.push(mySelTableColumns[a].tabStops.everyItem().leader);

                        }

                        if(mySelColNumberTabStops.toString().match(/[\d]/)){

                            var mySelColTabPosition =  mySelColWid-Math.round(app.selection[0].cells[0].texts[0].tabStops[0].position);

                        }

                        else{

                            var mySelColTabPosition =  0;

                       }

                        if(mySelTextContents.toString().match(/\t,/) && mySelColTextTabStops.toString().match(/ \./)){

                            myLeaderBoolean = true;

                        }

                        else {

                            myLeaderBoolean = false;

                        }

                        //now text indent

                        var myTextIndentBoolean = app.selection[0].cells.everyItem().texts.everyItem().firstLineIndent;

                        if(myTextIndentBoolean.toString().match(/-/)){

                            myTextIndentBoolean = true;

                        }

                        else {

                            myTextIndentBoolean = false;

                        }

                         //now Symbol our of margin

                        var myEachColTabStops = [];

                        var mySelTableColumns = app.selection[0].cells.everyItem().texts.everyItem().getElements();

                        for (var a=0; mySelTableColumns.length >a; a++){

                            myEachColTabStops.push(mySelTableColumns[a].tabStops.everyItem().alignmentCharacter);

                        }

                        if (myEachColTabStops.toString().match(/[*#@^(]/)){

                            myTabStopsOMCheck = true;

                        }

                        else {

                            myTabStopsOMCheck = false;

                         }

                    // end of myGet Columns Info ---------------------------------------------     

                     

                     

                    myCellDialog1();

                     

                     

                    function myCellDialog1(){

                       

                        var w = new Window("dialog", "Adjust Col._v1.0");

                              w.alignChildren = "left";

                        var g = w.add ("group");

                        var check1 = g.add ("checkbox", undefined, "Figure Col.?");

                               check1.value = true;

                        var g2 = w.add ("group");

                        var panel = g2.add("panel");

                               panel.orientation = "column";

                        

                        var my1row = panel.add("group");

                              my1row.orientation = "row";

                              my1row.alignment = "left";

                              my1row.add ("statictext", undefined, "Col. Width:");

                              var myText = my1row.add ("edittext", undefined, mySelColWid);

                                    myText.characters = 7;

                                    myText.active = true;

                     

                     

                              

                        var my2row = panel.add("group");

                              my2row.orientation = "row";

                              my2row.alignment = "left";

                     

                     

                                my2row.add ("statictext", undefined, "1n Col.:");

                                var myColArray = [];

                                var mySelTableColumns = app.selection[0].parent.columns.everyItem().getElements();

                                for (var a=0; mySelTableColumns.length >a; a++){

                                    myColArray.push(Number(a+1).toString());

                                }

                     

                     

                        var myDropdown = my2row.add ("dropdownlist", undefined, myColArray);

                              myDropdown.itemSize = [66,20];

                              myDropdown.selection = 0;      

                          

                        var my3row = panel.add("group");

                              my3row.orientation = "row";

                              my3row.alignment = "left";

                              my3row.add ("statictext", undefined, "Tab Position:");

                              var myTabPosition = my3row.add ("edittext", undefined, mySelColTabPosition);

                                    myTabPosition.characters = 6;

                                    myTabPosition.active = true;

                     

                     

                        var my4row = panel.add("group");

                              my4row.orientation = "row";

                              my4row.alignment = "left";

                        var mySymbol = my4row.add ("checkbox", undefined, "*#@^( out of Margin");

                              mySymbol.value =  myTabStopsOMCheck;

                        var my5row = panel.add("group");

                              my5row.orientation = "row";

                              my5row.alignment = "left";

                              my5row.add ("button", undefined, "Ok", {name: "ok"});

                              my5row.add ("button", undefined, "Cancel", {name: "cancel"});

                     

                     

                        check1.addEventListener ("click", function ()

                        {

                            w.close();

                            myCellDialog2();

                            }

                        );

                    var myWindow1 = w.show();

                        if (myWindow1 == true){

                       alert("apply window1 value");

                        }

                    }

                    function myCellDialog2(){

                                var w2 = new Window("dialog", "Adjust Col._v1.0");

                                      w2.alignChildren = "left";

                                var g = w2.add ("group");

                                var check1a = g.add ("checkbox", undefined, "Text Col.?");

                                       check1a.value = false;

                                var g2 = w2.add ("group");

                                var panel = g2.add("panel");

                                       panel.orientation = "column";

                                      

                                var my1row_w2 = panel.add("group");

                                      my1row_w2.orientation = "row";

                                      my1row_w2.alignment = "left";

                                      my1row_w2.add ("statictext", undefined, "Col. Width:");

                                      var myText_w2 = my1row_w2.add ("edittext", undefined, mySelColWid);

                                            myText_w2.characters = 7;

                                            myText_w2.active = true;

                                      

                                var my2row = panel.add("group");

                                      my2row.orientation = "row";

                                      my2row.alignment = "left";

                     

                     

                                        my2row.add ("statictext", undefined, "1n Col.:");

                                        var myColArray = [];

                                        var mySelTableColumns = app.selection[0].parent.columns.everyItem().getElements();

                                        for (var a=0; mySelTableColumns.length >a; a++){

                                            myColArray.push(Number(a+1).toString());

                                        }

                     

                     

                                var myDropdown = my2row.add ("dropdownlist", undefined, myColArray);

                                      myDropdown.itemSize = [66,20];

                                      myDropdown.selection = 0;

                         

                                var my3row = panel.add("group");

                                      my3row.orientation = "row";

                                      my3row.alignment = "left";

                                      my3row.add ("statictext", undefined, "Col. Indent (L):");

                                      var myColLIndent = my3row.add ("edittext", undefined, mySelColLIndnet);

                                            myColLIndent.characters = 5;

                                            myColLIndent.active = true;

                                var my4row = panel.add("group");

                                      my4row.orientation = "row";

                                      my4row.alignment = "left";

                                      my4row.add ("statictext", undefined, "Col. Indent (R):");

                                      var myColRIndent = my4row.add ("edittext", undefined, mySelColRIndnet);

                                            myColRIndent.characters = 5;

                                            myColRIndent.active = true;

                                var my5row = panel.add("group");

                                      my5row.orientation = "row";

                                      my5row.alignment = "left";

                                var myTextIndent = my5row.add ("checkbox", undefined, "Text Indent");

                                       myTextIndent.value = myTextIndentBoolean;

                                var my6row = panel.add("group");

                                      my6row.orientation = "row";

                                      my6row.alignment = "left";

                                var myLeader = my6row.add ("checkbox", undefined, "Leader");

                                       myLeader.value = myLeaderBoolean;

                                var my7row = panel.add("group");

                                      my7row.orientation = "row";

                                      my7row.alignment = "left";

                                      my7row.add ("button", undefined, "Ok", {name: "ok"});

                                      my7row.add ("button", undefined, "Cancel", {name: "cancel"});

                     

                     

                                 check1a.addEventListener ("click", function ()

                                {

                                    w2.close();

                                    myCellDialog1();

                                    }

                                );

                     

                     

                        var myWindow2 = w2.show();

                            if (myWindow2 == true){

                                alert("apply window2 value");

                            }           

                    }