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></SETFONTSTYLE>
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><CODE class=" language-jsl">
Sample output:
sel = {"A", "B"};
{Button( 1 )} // what is this?
Three things I would like to understand:
- 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?
- 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.
- 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></MODAL>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></TYPE>
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></TYPE>
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.
Re: Get selected item from a list box - changed behavior of JSL?Could be related to older version of JMP and some timings.