cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Ressel
Level VII

Get selected item from a list box - changed behavior of JSL?

Currently going through this beautiful instruction video on how to write a JSL script by  @David_Burnham

Up to 07 minutes and 28 seconds everything works as expected. Starting around 8 minutes and 13 seconds, precisely when the window is converted into a modal window, this code here throws an error:

 

// doesn't work:

lst = {"A", "B", "C"};
New Window("Select", << Modal, 
	Border Box(top(10), bottom(10), left(15), right(10),
		V List  Box(
			TextBox("Select the predictor variable", <<setfontstyle("bold")),
			Spacer Box(size(0,6)),
			lb = List Box(lst)
		)
	)
);
sel = lb << getSelected;
show(sel);

 

I think I found a solution here: How to get specific input values from modal windows to be placed in a JMP script to save. At least, when I run the below script and press the "OK" button of the modal window, sel returns a list with the selected values.

Script:

 

// works
NewWindow("Select", <<Modal,
	BorderBox(top(10), bottom(10), left(15), right(10),
	VListBox(
		TextBox("Select the predictor variable", <<setfontstyle("bold")),
		SpacerBox(size(0,6)),
			lb = ListBox(lst),
		
		// Custom buttons to capture selection before closing
			HListBox(
				ButtonBox("OK", sel = lb << getSelected; show(sel)), 
				ButtonBox("Cancel")
			)
		)
	)
);

 

Sample output:

sel = {"A", "B"};
{Button( 1 )} // what is this?

Three things I would like to understand:

  1. Is there something wrong with the original code I've posted at the top (// doesn't work) or has JSL changed behavior since the video was recorded?
  2. The return value {Button( 1 )}, I don't understand it. Why is it there? I am assuming it comes from the Button Box() but the scripting index isn't informative.
  3. Am I on the right track with the custom button? 

Edit:

A solution is even in the instruction video.

lst = {"A", "B", "C"};
NewWindow("Select", <<Modal,
	<<onClose(
		sel = lb << getSelected;
	),
	BorderBox(top(10), bottom(10), left(15), right(10),
		VListBox(
			TextBox("Select the predictor variable", <<setfontstyle("bold")),
			SpacerBox(size(0,6)),
			lb = ListBox(lst)
		)
	)
);

if (NItems(sel)==0, throw());
;
show(sel);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Get selected item from a list box - changed behavior of JSL?

1. After modal window closes, you cannot access the values anymore unless they are returned when << return result is used.

2. Button(1) just means that the OK was pressed and you can use that for example to control the flow of your script.

3. Yes, get values when OK is pressed is a good option.

 

I usually try first with << Return Result and if it doesn't work with my current window, then I get the values when OK button is pressed. I (almost) always add OK and Cancel buttons when modal dialog is being used even though they are not necessary Scripting Guide > Display Trees > Modal Windows in JSL > Construct a Modal Window .

Below is example using << Return Result

 

Names Default To Here(1);

lst = {"A", "B", "C"};

nw = New Window("Modal Dialog example",
	<<Type("Modal Dialog"),
	<<Return Result,
	V List Box(
		lb = List Box(lst),
		H List Box(
			Button Box("OK"),
			Button Box("Cancel")
		)
	)
);
show(nw);

If(nw["Button"] != 1,
	stop();
);

selvals = nw["lb"];

Show(selvals);

And case where it won't work as you would maybe like to (I want items which are added to collist box, not selected items)

 

 

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("Modal Dialog example",
	<<Type("Modal Dialog"),
	<<Return Result,
	H List Box(
		fcs = Filter Col Selector(),
		H List Box(
			Button Box("Add", clb << append(fcs << get selected)),
			clb = Col List Box()
		),
		H List Box(
			Button Box("OK",
				selvals = clb << get items;
			),
			Button Box("Cancel")
		)
	)
);
show(nw);

If(nw["Button"] != 1,
	stop();
);

Show(selvals);

 

 

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Get selected item from a list box - changed behavior of JSL?

1. After modal window closes, you cannot access the values anymore unless they are returned when << return result is used.

2. Button(1) just means that the OK was pressed and you can use that for example to control the flow of your script.

3. Yes, get values when OK is pressed is a good option.

 

I usually try first with << Return Result and if it doesn't work with my current window, then I get the values when OK button is pressed. I (almost) always add OK and Cancel buttons when modal dialog is being used even though they are not necessary Scripting Guide > Display Trees > Modal Windows in JSL > Construct a Modal Window .

Below is example using << Return Result

 

Names Default To Here(1);

lst = {"A", "B", "C"};

nw = New Window("Modal Dialog example",
	<<Type("Modal Dialog"),
	<<Return Result,
	V List Box(
		lb = List Box(lst),
		H List Box(
			Button Box("OK"),
			Button Box("Cancel")
		)
	)
);
show(nw);

If(nw["Button"] != 1,
	stop();
);

selvals = nw["lb"];

Show(selvals);

And case where it won't work as you would maybe like to (I want items which are added to collist box, not selected items)

 

 

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("Modal Dialog example",
	<<Type("Modal Dialog"),
	<<Return Result,
	H List Box(
		fcs = Filter Col Selector(),
		H List Box(
			Button Box("Add", clb << append(fcs << get selected)),
			clb = Col List Box()
		),
		H List Box(
			Button Box("OK",
				selvals = clb << get items;
			),
			Button Box("Cancel")
		)
	)
);
show(nw);

If(nw["Button"] != 1,
	stop();
);

Show(selvals);

 

 

-Jarmo
Ressel
Level VII

Re: Get selected item from a list box - changed behavior of JSL?

Thanks - as always, much appreciated! It's still puzzling that what is faulty here works in the video linked in my original posting.

jthi
Super User

Re: Get selected item from a list box - changed behavior of JSL?

Could be related to older version of JMP and some timings.

-Jarmo

Recommended Articles