Skip to main content
Inspiring
April 18, 2020
Answered

UI escape key returns alert dialog

  • April 18, 2020
  • 3 replies
  • 2837 views

I am stuck with a problem that I am not sure how to resolve and would like to ask for help from his community.

The Problem: 

Canceling the UI dialog via the escape key on the keyboard and the UI Cancel button returns an alert message.

function dialogTest()
{
// DIALOG
// ======
var dialog = new Window("dialog");
dialog.text = "Script Settings";
dialog.orientation = "row";
dialog.alignChildren = ["left","top"];
dialog.spacing = 10;
dialog.margins = 16;

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"});
group1.orientation = "column";
group1.alignChildren = ["fill","top"];
group1.spacing = 10;
group1.margins = 0;

// PANEL1
// ======
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
panel1.text = "User Settings";
panel1.orientation = "column";
panel1.alignChildren = ["left","top"];
panel1.spacing = 10;
panel1.margins = 15;

var radiobutton1 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton1"});
radiobutton1.text = "User 1";
radiobutton1.value = true;

var radiobutton2 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton2"});
radiobutton2.text = "User 2";

var radiobutton3 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton3"});
radiobutton3.text = "User 3";

var radiobutton4 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton4"});
radiobutton4.text = "User 4";


var checkbox1 = panel1.add("checkbox", undefined, undefined, {name: "checkbox1"});
checkbox1.text = "Checkbox 1";
checkbox1.alignment = ["left","center"];

// GROUP2
// ======
var group2 = dialog.add("group", undefined, {name: "group2"});
group2.orientation = "column";
group2.alignChildren = ["fill","top"];
group2.spacing = 10;
group2.margins = 0;

var ok = group2.add("button", undefined, undefined, {name: "ok"});
ok.text = "Save";

var cancel = group2.add("button", undefined, undefined, {name: "cancel"});
cancel.text = "Cancel";

dialog.items = {
ok: ok, // button ok
cancel: cancel // button cancel
};
dialog.items.array = [ok, cancel];

dialog.show();

newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1);

}

//=============================

dialogTest();

function newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1) {
alert("User 1 = " +radiobutton1.value); return
// alert("User 2 = " +radiobutton2.value);
// alert("User 3 = " +radiobutton3.value);
// alert("User 4 = " +radiobutton4.value);
// alert("Check Box 1 = " +checkbox1.value);
}
This topic has been closed for replies.
Correct answer Kukurykus
if (!(dialog.show() - 1)) newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1);

3 replies

Inspiring
April 19, 2020

Sorry, my mistake. I meant to mark your answer as correct. 

Kukurykus
Legend
April 19, 2020

Loll, now you reply outside of subthread, and the answer you marked, was mine indeed, but, not with solution I provided earlier, so I changed it myself eventually 😕😕

JJMack
Community Expert
Community Expert
April 18, 2020

It look like ESC end the Show Dialog.   Your script the preforms your  newfunction that does the alert  so its either true of false depending on which radio button is  checked.   You have set up not cancel test  so enter and cancel do the same thing.  The script ends after you acknowledge the alert.  

 

Esc Cancelled the Dialog not the script.  If fact on windows it often hard to stop a script with ESC or Break.  If a script is in an endless loop I usually  have to kill Photoshop the stop the a script. I doe not know if its a Photoshop problem of a widows problem.  I would think the Photoshop would need to field the ESC and Kill the script. Scripts do not get signal to terminate.  The System or Photoshop would need to terminate the script.

JJMack
Kukurykus
Legend
April 18, 2020

What different do you expect to happen after canceling (escaping) script if in the code at end is alert?

Inspiring
April 18, 2020

After pressing the escape key or cancel button, the UI dialog should terminate completely.

Kukurykus
KukurykusCorrect answer
Legend
April 18, 2020
if (!(dialog.show() - 1)) newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1);