Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Ensure Dialog Is Closed Before Proceeding

Return to Member Forum

  • Author
    Posts
    • #1201642
      Jeremy Howard
      Participant

      Hello all!

      I have been struggling with an issue that has been driving me nuts for a while and I am hoping someone can help!

      Let’s say that I have a button in a custom dialog (such as “Continue”) that should close the active dialog and run a function. If I try something like this:

      ——————————————————————————————-
      var aDialog = new Window(‘dialog’, “Window Name”);
      aDialog.preferredSize = [300,100];
      aDialog.orientation = ‘column’;
      aDialog.add(‘statictext’, undefined, “Some dialog contents here.”);

      var myButtonGroup = aDialog.add(‘group’);
      var cancelButton = myButtonGroup.add(‘button’, undefined, “Cancel”,{name: “Cancel”});
      var proceedButton = myButtonGroup.add (‘button’, undefined, “Continue”,{name: “proceedButton”});

      proceedButton.onClick = function() {
      aDialog.close();
      app.doScript(mainFunction, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Main Function”);
      }

      aDialog.show()

      function mainFunction(){
      app.selection = app.activeDocument.pageItems[0];
      }
      ——————————————————————————————————–

      Then I will get an error in my function that says, “Cannot handle the request because a modal dialog or alert is active”. This is very confusing to me because I very clearly told the dialog to close prior to running the function.

      My workaround has been to use palettes instead of dialogs but the same sort of issue can occur there as well. For example, I am currently working on a script where I am using a palette that should probably be a dialog. I want the palette to close and I want a progress bar to show when I click “Continue” on that palette. Instead, what I get is a frozen view of the main palette for the first 1/3 of the called function and a progress bar that displays once the script is already 33% done.

      Ideally, I would just get this working properly as a dialog but I’ll take what i can get at this point.

      Here are my specs:
      Mac OS X 10.13.6
      InDesign 2020 (15.0)

    • #14323609
      Jeremy Howard
      Participant

      Update – Issue Has Been Resolved!

      I finally found the solution I was looking for after a whole bunch of digging around and reading. Here is what I figured out:

      ——————————————————————————————————–——————————————————————————————————–——————————————————————————————————–
      var aDialog = new Window(‘dialog’, “Dialog Title”,);
      aDialog.orientation: ‘column’
      aDialog.preferredSize: [300,100]
      aDialog.add(‘statictext’, undefined, “Some dialog contents here.”);

      var myButtonGroup = aDialog.add(‘group’);
      var cancelButton = myButtonGroup.add(‘button’, undefined, “Cancel”,{name: “Cancel”});
      var proceedButton = myButtonGroup.add (‘button’, undefined, “Continue”,{name: “proceedButton”});

      proceedButton.onClick = function(){
      aDialog.close(1)
      }

      var dialogResult = aDialog.show()

      if(dialogResult == 1){
      app.doScript(mainFunction, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Undo Name”);
      }else if (dialogResult== 2){
      alert(“You clicked the Cancel button!”);
      exit(0);
      }

      function mainFunction(){
      app.selection = app.activeDocument.pageItems[0];
      }
      ——————————————————————————————————–——————————————————————————————————–——————————————————————————————————–

      This works as i was hoping and will run the function without that pesky error!

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Forum Ads