How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?In the following script, I would like to do the following:
Based on the selection of TestTech, I want the appropriate TestStage check box list to appear (appear is preferred, if not become active if all options need to be visible). So,
- if Tech1 is selected, all TestSages with _Tech1 should be available to the user for selection
- if Tech2 is selected, all TestSages with _Tech2 should be available to the user for selection. This list is commented below
- if Tech3 is selected, all TestSages with _Tech3 should be available to the user for selection. This list is commented below, and so on.
I would also like "Select All" option to be available under each list.
How to do this?
Names Default To Here( 1 );
Clear Log ();
listInd = {};
returned2 = {};
win = New Window( "Select Tech & TestStage", << modal,
V List Box (
tb1=Text Box("Select Tech", << set font style("bold")),
cb1 = List Box(
{"Tech1", "Tech2", "Tech3"},
returned1 = (cb1 << Get Selected());
listInd= cb1 << Get Selected Indices;
),
tb1=Text Box("Select one or more TestStage", << set font style("bold")),
cb2 = Check Box(
{"Sage1_Tech1", "Sage2_Tech1", "Sage3_Tech1", "Sage4_Tech1", "Sage5_Tech1", "Sage6_Tech1"},
//{"Sage1_Tech2", "Sage2_Tech2", "Sage3_Tech2", "Sage4_Tech2", "Sage5_Tech2", "Sage6_Tech2"},
//{"Sage1_Tech3", "Sage2_Tech3", "Sage3_Tech3", "Sage4_Tech3", "Sage5_Tech3", "Sage6_Tech3"},
returned2 = (cb2 << Get Selected());
),
tb3=Text Box("Query TestDate (last 6 months selected by default)", << set font style("bold")),
end_date = Today();
start_date = Date Increment(end_date, "month", -6, "actual");
cb3 = H List Box(
Text Box("From:"),
scal = Number Edit Box(
start_date,
<<SET format=""></SET>
Automation and ScriptingWindowsRe: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?This might give you some ideas what you could do
Names Default To Here(1);
lb_values = {"Tech1", "Tech2", "Tech3"};
cb_values = {"Sage1_Tech1", "Sage2_Tech1", "Sage3_Tech1", "Sage4_Tech1", "Sage5_Tech1", "Sage6_Tech1",
"Sage1_Tech2", "Sage2_Tech2", "Sage3_Tech2", "Sage4_Tech2", "Sage5_Tech2", "Sage6_Tech2",
"Sage1_Tech3", "Sage2_Tech3", "Sage3_Tech3", "Sage4_Tech3", "Sage5_Tech3", "Sage6_Tech3"
};
expr_update_cb = Expr(
cur_sel = lb << get selected;
If(N Items(cur_sel),
cur_cb_values = Filter Each({val}, cb_values,
cur_tech = Word(2, val, "_");
Contains(cur_sel, cur_tech);
);
,
cur_cb_values = cb_values;
);
cb2 << Set items(cur_cb_values);
);
win = New Window("Select Tech & TestStage", <<MODAL></MODAL>Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi Thanks. Running your script starts off by showing all TestStages under TestStage by default (pasted below) and then once a Tech is selected, it behaves as needed.
Could the script be modified to not show nothing first under TestStage selection text and then once the Tech is selected, show the appropriate/available TestStages?

Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?You could initialize the check box with empty list instead of cb_values.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi I have already tried with
cb_values = {};but I think I am not placing this correctly. Where should this statement go?
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?This is the place where you set those values first time

also if you want it to be always empty when no selections are done you will also have to make small modification to expr_update_cb
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi . In that case I did place the
cb_values = {};correctly, but did not do the small modification to expr_update_cb. Just placing the above line before cb2= Check Box(... does not do what's needed once Tech is selected. Thinking.......
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?Initialize Check Box with empty list not cb_values (they are different things).
Within the expression this is the part you have to consider (and understand)

Why is if statement used here? What would happen if we go to else? What would happen if we don't have it, we have an empty list and go to Filter Each?
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi Thanks for the pointers, I tried last night but without success so far.
This is how I understand the requirement, if none of the items are selected in under lb then cb2 should not show. cb2 should show only when N Items(cur_sel) â¥1.
However, expr_update_cb fires only when one or more items are selected in lb.
It is not clear to me how to modify expr_update_cb to be executed when nothing is selected under lb.
Should the requirement of not showing anything under cb2 be handled with an if/else statement around lb i.e. if nothing is selected under lb, do not show cb2?
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?Names Default To Here(1);
lb_values = {"Tech1", "Tech2", "Tech3"};
cb_values = {"Sage1_Tech1", "Sage2_Tech1", "Sage3_Tech1", "Sage4_Tech1", "Sage5_Tech1", "Sage6_Tech1",
"Sage1_Tech2", "Sage2_Tech2", "Sage3_Tech2", "Sage4_Tech2", "Sage5_Tech2", "Sage6_Tech2",
"Sage1_Tech3", "Sage2_Tech3", "Sage3_Tech3", "Sage4_Tech3", "Sage5_Tech3", "Sage6_Tech3"
};
expr_update_cb = Expr(
cur_sel = lb << get selected;
If(N Items(cur_sel),
cur_cb_values = Filter Each({val}, cb_values,
cur_tech = Word(2, val, "_");
Contains(cur_sel, cur_tech);
);
,
cur_cb_values = cb_values;
);
cb2 << Set items(cur_cb_values);
);
win = New Window("Select Tech & TestStage", <<MODAL></MODAL>Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi Not sure why you repeat posted your original script, but this is where I have got to, still not working as needed, perhaps end looks near
?
Names Default To Here(1);
clear log ();
listInd = {}; p = N Items (listInd);
lb_values = {"Tech1", "Tech2", "Tech3"};
cb_values = {"Sage1_Tech1", "Sage2_Tech1", "Sage3_Tech1", "Sage4_Tech1", "Sage5_Tech1", "Sage6_Tech1",
"Sage1_Tech2", "Sage2_Tech2", "Sage3_Tech2", "Sage4_Tech2", "Sage5_Tech2", "Sage6_Tech2",
"Sage1_Tech3", "Sage2_Tech3", "Sage3_Tech3", "Sage4_Tech3", "Sage5_Tech3", "Sage6_Tech3"
};
expr_update_cb = Expr(
cur_sel = lb << get selected;
If(N Items(cur_sel), cur_cb_values = Filter Each({val}, cb_values, cur_tech = Word(2, val, "_"); Contains(cur_sel, cur_tech))
,
cur_cb_values = cb_values;
);
p = N Items(cur_sel);
cb2 << Set items(cur_cb_values); show (cur_cb_values);
);
win = New Window("Select Tech & TestStage", <<MODAL></MODAL>
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?Most likely my broken ctrl didn't let me copy correct script and I posted too quickly. It should be fixed now.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi Thanks. Your updated script from today is working. I would be interested to know if the way I was doing it today (my script from today) is an incorrect approach.
Also, why does the date query not show if I put tb3 and cb3 sections at the top i.e. above tb1?
(idea is to get the user to choose the dates before anything else)
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?My guess is that you are missing "," or you have ";" in wrong place
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi my "," placement seems correct but I still cannot get date query to work when placed at the top.
Also, how to return the value selected by "select all"? My original placement for returned2 only seems to work for manual selection.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?I would just get all values into variables when user presses OK not when user changes their selections.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi Thanks, but I can only get manual selections retuned with my placement of returned2 inside the cb2=Check Box (.. .
Please could you point me to where to place cb2 << Get Selected(); to fire only when the user presses OK.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window? Scripting Guide > Display Trees > Modal Windows in JSL > Construct a Modal Window gives explanation of new windows using modal. And this should give an example where to place commands to get values into variables
Names Default To Here(1);
nw = New Window("Example", <<MODAL></MODAL>
You could also place that to << On Validate or << On Close (see Scripting Index for example and some explanation) but I usually place them inside the OK button.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi, Thanks.
show(cb_sel);
works.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi While I am on this topic (and not creating a new thread asking a new but related question), I am wondering if it is possible to show a text showing the user what each test stage did when the user selects it. Example pasted below. Text only shows when selection is made and remains until unchecked.

Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?It is definitely possible, but how to make it robust and easy to use can be different thing. Below is one quick option that came to my mind (most likely there are better options)
Names Default To Here(1);
cb_sel = {};
nw = New Window("Example", <<MODAL></MODAL>Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi Thanks. This is exactly what is needed but I would struggle to adapt this to my original example in this thread (my first post, with Tech and TestStage script). If you could please show it for one/two selections, I should be able to do the rest.
I can see the text for each test stage needs to be pre-defined.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?If I write it for one/two selections I would basically rewrite the whole script as there is quite a lot what would have to be taken into account. Also, you don't have to pre-define them if you can determine what they should be in some other way.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?@jthi No problem. Thanks for your help so far on this topic. The script you used for demo appears to require each check box to be dealt with individually for additional text, whereas in my original case all options come in a single list.
Could you please give me some pointers so that I can make a start on my original/first script in this post?
I will try to do it myself and then comeback with specific questions.
Also, in working my case, the text for each selected Test Stage would be a list of predefined tested parameters. For e.g. for the first test stage {A, B}, for the second, {A, B, C, L,M}.
Re: How to get check boxes to be change (or become visible or active) based on a previous selection in a modal window?Use associative array to store your different lists, create expressions/functions to create a collector for checkboxes and ifboxes.
This doesn't use modal window, as it is much easier to develop when not using one as you can easily test different gets and such from the script editor
Names Default To Here(1);
tech_options = {"Tech1", "Tech2"};
stages_tech1 = {"Sage1_Tech1", "Sage2_Tech1"};
stages_tech1_text = {"First Level Tech1", "Second Level Tech1"};
stages_tech2 = {"Sage1_Tech2", "Sage2_Tech2"};
stages_tech2_text = {"First Level Tech2", "Second Level Tech2"};
aa_tech = Associative Array();
aa_tech["Tech1"] = Associative Array(stages_tech1, stages_tech1_text);
aa_tech["Tech2"] = Associative Array(stages_tech2, stages_tech2_text);
get_cbs = Expr(
cbs = cb_lub << XPath("//CheckBoxBox");
);
update_checkboxes = Expr(
tech_selections = lb << get selected;
cb_lub = Lineup Box(N Col(2));
For Each({tech_selection}, tech_selections,
For Each({{stage, text}}, aa_tech[tech_selection],
cb_lub << Append(Check Box(stage, << Set Function(function({this},
(this << sib) << Set(this << get);
))));
cb_lub << Append(IfBox(0, Text Box(text)))
);
);
Try((cb_collector << child) << Delete Box());
cb_collector << Append(cb_lub);
);
win = New Window("Select Tech & TestStage",
V List Box(
H List Box(
Spacer Box(Size(0, 300)), // to force height
V List Box(
Spacer Box(Size(300, 0)), // to force width
tb1 = Text Box("Select Tech", <<SET font="" style=""></SET>
