cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Neo
Neo
Level VI

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 checkbox 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(Format("yyyy-mm-dd")),
			<<SetFunction(Function({this}, start_date = scal << Get)),
			<<Set Show Spin Box(1)
		),
		Spacer Box(Size(20, 20)),
		Text Box("To:"),
		ecal = Number Edit Box(
			end_date,
			<<Set Format(Format("yyyy-mm-dd")),
			<<SetFunction(Function({this}, end_date = ecal << Get)),
			<<Set Show Spin Box(1)
		),

	);
	
),	
	
);

Technology = eval (returned1[1]); show (Technology);
TestStages  = eval (returned2); show (TestStages);
TestStageOne  = TestStages[1]; show (TestStageOne );

sdt = Munger( Format Date( start_date, "yyyy-mm-dd" ), 1, "T", " " );
edt = Munger( Format Date( end_date, "yyyy-mm-dd" ), 1, "T", " " ); 

Show( sdt, edt );

 

 

When it's too good to be true, it's neither
24 REPLIES 24
jthi
Super User

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, <<return result,
	<< On Validate(
		cb_sel = ((btn << top parent) << XPath("//CheckBoxBox")) << get selected; // This will be a list of lists
		1;
	),
	Panel Box("Options",
		V List Box(
			Spacer Box(Size(150,0)),
			Lineup Box(N Col(2),
				Check Box({"One"}, << Set Function(function({this},
					(this << sib) << Set(this << get)
				))),
				If Box(0, Text box("One did this")),
				Check Box({"Two"}, << Set Function(function({this},
					(this << sib) << Set(this << get)
				))),
				If Box(0, Text box("Two that")),
				Check Box({"Three"}, << Set Function(function({this},
					(this << sib) << Set(this << get)
				))),
				If Box(0, Text box("Three this"))
			)
		)
	),
	Panel Box("Actions",
		Lineup Box(N Col(2),
			btn = Button Box("OK"),
			Button Box("Cancel")
		)
	)
);

show(cb_sel);
-Jarmo
Neo
Neo
Level VI

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. 

When it's too good to be true, it's neither
jthi
Super User

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.

-Jarmo
Neo
Neo
Level VI

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}.

When it's too good to be true, it's neither
jthi
Super User

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("bold")), 
				lb = List Box(tech_options,
					update_checkboxes
				), 
				tb1 = Text Box("Select one or more TestStage", <<set font style("bold")),
				V List Box(
					cb_collector = V List Box(
						cb_lub = Lineup Box(N Col(2))
					)
				)
			)
		),
		H List Box(
			Button Box("Select All",
				get_cbs;
				If(N Items(cbs),
					cbs << Set All(1, Run Script(1));
				)
			),
			Button Box("Clear All",
				get_cbs;
				If(N Items(cbs),
					cbs << Set All(0, Run Script(1));
				)
			),
			Button Box("Get Values",
				get_cbs;
				If(N Items(cbs),
					cur_selection = {};
					For Each({cb_vals}, cbs << get selected,
						Insert Into(cur_selection, cb_vals)
					);
				,
					cur_selection = {}
				);
			)
		)
	)
);

jthi_0-1702501703189.png

 

-Jarmo