2 Replies Latest reply on Aug 7, 2018 7:09 AM by markp9652695

    JS Dialog with Radio Buttons (CS6)

    markp9652695 Level 1

      JS Dialog with Radio Buttons (CS6)

       

      I am trying to create a simple dialog with two radio buttons, but no buttons are visible.

      Please help me correct the errors. The three dialogs that I am working with are described below.

       

      Attempt #1: With radio buttons that will not display.

       

      try {

      //provide variable to hold user's response

      var userResponse = dialogWRow ("Dialog Name", true, "Label Here");

      userResponse;

      } catch (e) {

      alert ("User Cancelled");

      }

       

      function dialogWRow (dlgName, cancelIt, dlgLabel) {

      //make sure that user interaction levels will allow a dialog

      var origLevel = app.scriptPreferences.userInteractionLevel;

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

      //create the dialog

      var dlgRef = app.dialogs.add({name:dlgName, canCancel:cancelIt});

      //add a column

      var dlgColumn = dlgRef.dialogColumns.add();

      var dlgRow = dlgColumn.dialogRows.add();

          var RadioBtnGrp = radiobuttonGroups.add();

          with (RadioBtnGrp){

              var radio_1 = radiobuttonControls.add({staticLabel:"radio button 1", checkedState:true});

              var radio_2 = radiobuttonControls.add({staticLabel:"radio button 2", checkedState:false});

              }

      //show the dialog and capture the result

      if (dlgRef.show() == true) {

      if(RadioBtnGrp.selectedButton == 0){

      app.open(File ("path\\file 1.indd"));

      }

      else if(RadioBtnGrp.selectedButton == 1){

      app.open(File ("path\\file 2.indd"));

      }

          // var nameFieldVal = nameField.editContents;

      } else {

      //destroy the dialog before throwing exception

      dlgRef.destroy();

      //restore script preference

      app.scriptPreferences.userInteractionLevel = origLevel;

      throw ("User cancelled");

      }

      //destroy the dialog; script doesn't get here if user cancels

      dlgRef.destroy();

      //restore script preference

      app.scriptPreferences.userInteractionLevel = origLevel;

      return nameFieldVal;

      }

      -----------------

      Dialog #2: Only OK and Cancel buttons

       

      try {

      //provide variable to hold user's response

      var userResponse = dialogWRow ("Dialog Name", true, "Label Here");

      userResponse;

      } catch (e) {

      alert ("User Cancelled");

      }

       

      function dialogWRow (dlgName, cancelIt, dlgLabel) {

      var origLevel = app.scriptPreferences.userInteractionLevel;

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

      var dlgRef = app.dialogs.add({name:dlgName, canCancel:cancelIt});

      //add a column

      var dlgColumn = dlgRef.dialogColumns.add();

      var dlgRow = dlgColumn.dialogRows.add();

       

      if (dlgRef.show() == true) {

      var nameFieldVal = nameField.editContents;

      } else {

      //destroy the dialog before throwing exception

      dlgRef.destroy();

      //restore script preference

      app.scriptPreferences.userInteractionLevel = origLevel;

      throw ("User cancelled");

      }

      //destroy the dialog; script doesn't get here if user cancels

      dlgRef.destroy();

      //restore script preference

      app.scriptPreferences.userInteractionLevel = origLevel;

      return nameFieldVal;

      }

      ---------------------

      Dialog #3: OK and Cancel buttons and static text label.

       

      try {

      //provide variable to hold user's response

      var userResponse = dialogWRow ("Dialog Name", true, "Label Here");

      userResponse;

      } catch (e) {

      alert ("User Cancelled");

      }

       

      function dialogWRow (dlgName, cancelIt, dlgLabel) {

      var origLevel = app.scriptPreferences.userInteractionLevel;

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

      var dlgRef = app.dialogs.add({name:dlgName, canCancel:cancelIt});

      //add a column

      var dlgColumn = dlgRef.dialogColumns.add();

      var dlgRow = dlgColumn.dialogRows.add();

      //add widgets to row

      dlgRow.staticTexts.add({staticLabel: "Your name here:"});

      if (dlgRef.show() == true) {

      var nameFieldVal = nameField.editContents;

      } else {

      //destroy the dialog before throwing exception

      dlgRef.destroy();

      //restore script preference

      app.scriptPreferences.userInteractionLevel = origLevel;

      throw ("User cancelled");

      }

      //destroy the dialog; script doesn't get here if user cancels

      dlgRef.destroy();

      //restore script preference

      app.scriptPreferences.userInteractionLevel = origLevel;

      return nameFieldVal;

      }