Copy link to clipboard
Copied
The scriptUI builder from Joonas has reduced the amount of time that it takes to create a GUI, which is fantastic.
Presuming that I have my code already working without a GUI, I am really struggling to work out how to test and link up a function or other "result" to the GUI elements in the window.
Take for example this code, it is a simple test, it only has two radio buttons and an OK and Cancel button.
I have worked out how to test and return that it is "true" if a radio button is selected. This also works the same for checkboxes. All good so far.
However, I don't know what to do with the OK and cancel buttons. If I select a radio button and cancel, the function called by the button is executed. Obviously the expectation is that if cancel is pressed, then nothing happens.
Do I need to do anything for the OK button?
I am finding it hard looking at existing code and have not had much success with othe resources such as forum searches.
There must be a resource that simply explains this stuff with working examples? It is taking hours of research for me to get a UI element to do something correctly, so am I missing a basic resource?
This is of course just the start of my questions, there are many different UI controls (dropdowns, fields etc)... Which I'll get to.
I was writing the answer before you posted the code:
// SHOW THE WINDOW
function yourCode() {
function button1result() {
alert("You selected Button 1");
}
function button2result() {
alert("You selected Button 2");
}
if (radioButton1.value === true) {
button1result();
}
if (radioButton2.value === true) {
button2result();
}
}
myDialogWindow.show() - 2 ? yourCode() : alert('Exit!')
dropdownMenu.selection.index
Copy link to clipboard
Copied
You probably missed my correct answer in other post: Jun 25, 2021 🙂
Put that in place of buttonActions() function content and run the code.
Copy link to clipboard
Copied
Don't forget that every form-item has a few methodes that deal directly with events.
onActivate, onClick, onDeactivate and then some more. THese allow for more granular control of what your buttons and other elements do, for instance:
okButton.onClick = function(){
var theText = "you chose option : " + dropDown.selection.index;
alert(theText );
}
(more info per element here: https://theiviaxx.github.io/photoshop-docs/ScriptUI/index.html)
As far as I understand Cancel and Ok buttons have specific behavior, but these only pertain to the window, so any script that runs after the dialog closes runs regardless what is clicked (ok/cancel). What I tent to do to work around this is to have a variable "processed" setup as false before the dialog and have the ok-button onclick action change that to true:
var processed = false;
/* dialogwindow code */
buttonOK.onclick = function(){
/* processing code */
processed = true;
}
/* rest of code follows: */
if( processed == true ){
/*application code */
} else {
//do nothing
}
Copy link to clipboard
Copied
...and onDoubleClick for ListBox when using addEventListener to enrich a code even more 🙂
Find more inspiration, events, and resources on the new Adobe Community
Explore Now