Copy link to clipboard
Copied
Hello guys! I'm trying to add a Checkbox for the purpose of adding a companion option to the Master Script ... It would work like this:
• Radio button: Main Script (1st Script)
• Checkbox: Complementary script (2nd Script) (Optional)
I tried to create a very basic little Script, my problem is that when I mark the Checkbox option, the "2nd Script" executes before "1st Script" even before confirming with the OK button. Guys how to solve this?
var win = new Window("dialog", "Radio and Checkbox");
win.orientation = "row";
win.alignChildren = "top"; // insert this line
var radio_group = win.add('panel', undefined, "Main Event");
radio_group.alignChildren = "left";
radio_group.add("radiobutton", undefined, "Main");
// Checkbox Grupo:
win.displayFunc = win.add('panel', [12,10,90,83], "Add this option"); //dimensione riga
// Option:
win.displayFunc.actualBtn = win.displayFunc.add('checkbox', [10,10,100,35], 'Optional');
win.displayFunc.actualBtn.onClick = function (event)
{ // Execulta Script Border White: (Inicio)
alert("2: Hello! I am the Optional script!")
}// Execulta Script Border White (Final )
// Botões (OK /Cancelar)
var btnGroup = win.add("group"); btnGroup.orientation = "column";
btnGroup.add ('button', {x:90, y:125, width:80, height:25}, 'Ok', {name:'ok'});
btnGroup.add ('button', {x:240, y:125, width:80, height:25}, 'Cancel', {name:'cancel'});
// set dialog defaults
radio_group.children[0].value = true;
function selected_rbutton(rbuttons) {
for (var i = 0; i < rbuttons.children.length; i++) {
if (rbuttons.children.value == true) {
return rbuttons.children.text;
}
}
}
//Scripts Que executam a Função Principal-------------------------------------------------------------------------
// Linkar com os Scrips.jsx
if (win.show() == 1) {
var chosenRadioButton = selected_rbutton(radio_group);
switch (chosenRadioButton) {
// Main.jsx
case "Main":
alert("1: Hello! I am the Main script!")
break;
//Final Scrips 1
//---------------------------------------------------------
}
}
Here's your script with some checkboxes added.
...var w = new Window("dialog", "Test");
w.orientation = "row";
w.alignChildren = "top"; // insert this line
var radio_group = w.add('panel', undefined, "Radio");
radio_group.alignChildren = "left";
radio_group.add("radiobutton", undefined, "Radio 1");
radio_group.add("radiobutton", undefined, "Radio 2");
var check_gp = w.add('panel',undefined,'check boxes');
check_gp.orien
Copy link to clipboard
Copied
The main event is alway run so a radio button is not required.
var win = new Window("dialog", "Radio and Checkbox");
win.orientation = "row";
win.alignChildren = "top"; // insert this line
//No radio button required as the main is always run.
// Checkbox Grupo:
win.displayFunc = win.add('panel', undefined, "Add this option"); //dimensione riga
// Option:
win.displayFunc.actualBtn = win.displayFunc.add('checkbox', undefined, 'Optional');
// Botões (OK /Cancelar)
var btnGroup = win.add("group"); btnGroup.orientation = "column";
win.ok = btnGroup.add ('button', {x:90, y:125, width:80, height:25}, 'Ok', {name:'ok'});
btnGroup.add ('button', {x:240, y:125, width:80, height:25}, 'Cancel', {name:'cancel'});
// set dialog defaults
win.displayFunc.actualBtn.value = true;
win.ok.onClick=function(){
win.close();
alert("This.the main script");
//rest of main script
//Chrck is secondary script required
if(win.displayFunc.actualBtn.value){
alert("This is the second script");
}
}
win.show();
Copy link to clipboard
Copied
SuperMerlin, Firstly I want to thank you for the huge contribution you have given here in this forum: Anyway, I'm trying very hard to try to better understand ScriptUI, messe case involving Radio Buttons with Checboox. This script you wrote is very good, practical, and very objective. Now two curiosities have arisen and I will not discard this opportunity to ask you:
1: Should I Need to Add Two or Three Radio Buttons? (Main event)
2: Should I need to add the second option in Checkebox?
This information would be fundamental for my future projects:Thank you!
Copy link to clipboard
Copied
Radio buttons are only used if you have two or more options and you want only one selected. Checkboxes are used if you want one or more options turned on or off. You can have multiple checkboxes on at the same time. So it's up to you how you want your script to run and what options are set at the time the script runs. Most scripts have an "Okay" and "Cancel" button for having the script run, not a radio button.
Copy link to clipboard
Copied
That's right Chuck Uebele: I showed the simple example at the beginning with only one radio option and one with checkbox just to ease my question: But my goal is yes, you can add More than one Radio option and with some options Check box . I managed to do this, the problem is that the second event was run even before the main event without confirmation of the OK button! My knowledge in Photoshop Scripting is only 10% only. The SuperMerlim script is very good: I just need to create more options and know where to add my scripts to their corresponding "Radio as well as checkbox" options in the order: "First Radio" .... "Second-Checkbox ". I believe that an Interface Model from two options I will be able to compose and know how to make the modifications that serve my purposes. Thanks for listening
Copy link to clipboard
Copied
SuperMerlin cleaned up your panel, and gave it a better flow. Looking at your original code, you have an onClick function for the check box that will display the alert no matter what the value is of the check box. You really don't need an onClick function for it. If your intent is to run the optional script, you really don't want it to run when the check box is clicked. It's better to have one main okay button then have the script run all the sections of the script that were selected. So if you want to run just the main script. just have the optional checkbox unchecked then have your script check it's value when the okay button is pressed. If you just want to run the optional script and not the main one, then you need a check box for that rather than a radiobutton. The sequence of how your script runs is based on how you arrange your code, as SuperMerlin has done with his revamp of your code. As an example here's a screen shot of the UI of one of my scripts. I highlighted the radiobuttons in red. They are for options that require only one choice. Most the other controls in the script are checkboxes to turn off or on various parts of the script that I may or may not want to run, like making proofsheets.
Copy link to clipboard
Copied
I understood your explanation! I do not know how to make it happen! I have here another basic example with two options with (Radio Button). "Radio 1" and "Radio 2". I would like you to even if possible, add to my code a checkbox with 2 options of choice? Use alert scripts to represent each option, eg "alert option 1", "alert option 2". (Then I modify the alert scripts).
The goal is to execute all sections of the script that were selected in the main script after clicking the OK button! Only that. Thank you
var w = new Window("dialog", "Test");
w.orientation = "row";
w.alignChildren = "top"; // insert this line
var radio_group = w.add('panel', undefined, "Radio");
radio_group.alignChildren = "left";
radio_group.add("radiobutton", undefined, "Radio 1");
radio_group.add("radiobutton", undefined, "Radio 2");
var btnGroup = w.add("group");
btnGroup.orientation = "column";
btnGroup.add('button', { x: 90, y: 125, width: 90, height: 25 }, 'Ok', { name: 'ok' });
btnGroup.add('button', { x: 240,y: 125, width: 90, height: 25 }, 'Cancel', {name: 'cancel'});
// set dialog defaults
radio_group.children[0].value = true;
function selected_rbutton(rbuttons) {
for (var i = 0; i < rbuttons.children.length; i++) {
if (rbuttons.children.value == true) {
return rbuttons.children.text;
}
}
}
// Linkar com os Scrips.jsx
if (w.show() == 1) {
var chosenRadioButton = selected_rbutton(radio_group);
switch (chosenRadioButton) {
// Scrips Radio 1
case "Radio 1":
alert("This is the Radio 1 script");
break;
//---------------------------------------------------------
// Scrips Radio 2
case "Radio 2":
alert("This is the Radio 2 script");
break;
//---------------------------------------------------------
}
}
Copy link to clipboard
Copied
Here's your script with some checkboxes added.
var w = new Window("dialog", "Test");
w.orientation = "row";
w.alignChildren = "top"; // insert this line
var radio_group = w.add('panel', undefined, "Radio");
radio_group.alignChildren = "left";
radio_group.add("radiobutton", undefined, "Radio 1");
radio_group.add("radiobutton", undefined, "Radio 2");
var check_gp = w.add('panel',undefined,'check boxes');
check_gp.orientation = 'column';
check_gp.alignChildren = ['left','top'];
var check1 = check_gp.add('checkbox',undefined,'checkbox 1');
var check2 = check_gp.add('checkbox',undefined,'checkbox 2');
check1.value = true;
check2.value = true;
var btnGroup = w.add("group");
btnGroup.orientation = "column";
btnGroup.add('button', { x: 90, y: 125, width: 90, height: 25 }, 'Ok', { name: 'ok' });
btnGroup.add('button', { x: 240,y: 125, width: 90, height: 25 }, 'Cancel', {name: 'cancel'});
// set dialog defaults
radio_group.children[0].value = true;
function selected_rbutton(rbuttons) {
for (var i = 0; i < rbuttons.children.length; i++) {
if (rbuttons.children.value == true) {
return rbuttons.children.text;
}
}
}
// Linkar com os Scrips.jsx
if (w.show() == 1) {
var chosenRadioButton = selected_rbutton(radio_group);
switch (chosenRadioButton) {
// Scrips Radio 1
case "Radio 1":
alert("This is the Radio 1 script");
break;
//---------------------------------------------------------
// Scrips Radio 2
case "Radio 2":
alert("This is the Radio 2 script");
break;
//---------------------------------------------------------
}
if(check1.value){alert('checkbox 1 is checked')}
else{alert('checkbox 1 is not checked')}
if(check2.value){alert('checkbox 2 is checked')}
else{alert('checkbox 2 is not checked')}
}
Copy link to clipboard
Copied
Chuck Uebele It worked right here! It works that's a wonder ... Now it's good for me to understand how the structure works, and now I know how to add my scripts to every event I create. Thank you very much. Thank you also to the SuperMerlin