Wednesday, August 1, 2018

ScriptUI Dialog with interacting buttons

ScriptUI Dialog with interacting buttons


Heres a simple script I just banged out to show a simple case of two buttons interacting with each other in a ScriptUI modal dialog:
//DESCRIPTION: Sample Dialog

myDlg = new Window(dialog, Example);
myDlg.orientation = row;

// Add action buttons
myDlg.btn1 = myDlg.add(button, undefined, Disable Him);
myDlg.btn2 = myDlg.add(button, undefined, Disable Him);
myDlg.closeBtn = myDlg.add(button, undefined, Close);

// Add button functions
myDlg.btn1.onClick = function() {
  if (this.text == Disable Him) {
    this.text = Enable Him;
    myDlg.btn2.enabled = false;
  } else {
    this.text = Disable Him;
    myDlg.btn2.enabled = true;
  }
}

myDlg.btn2.onClick = function() {
  if (this.text == Disable Him) {
    this.text = Enable Him;
    myDlg.btn1.enabled = false;
  } else {
    this.text = Disable Him;
    myDlg.btn1.enabled = true;
  }
}

myDlg.closeBtn.onClick = function() {
  this.parent.close(1);
}

result = myDlg.show();
if (result == 1) {
  alert("You used the Close button");
}
Notice that if you close the dialog by hitting the Escape key rather than clicking the Close button, you do not get the alert.

go to link download