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:
- 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,
<<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);