cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
pmroz
Super User

How to initialize things in a modal window?

I have a modal window and I need to preset some values in a combobox.  I can do this in a non-modal window but not in the modal window.  Anyone know how?

Here's an example from the JSL manual.  This is a non-modal window, so the item "Two" is preselected in the combobox.

New Window( "Example",

      cb = Combo Box(

            {"One", "Two", "Three"},

            selection = cb << GetSelected();

            Print( "Selected: " || selection );

      )

);

cb << Set( 2 );


If I change it to a modal window I can't preset "Two" for the combobox:

New Window( "Modal Example", << modal,

      cb = Combo Box(

            {"One", "Two", "Three"},

            selection = cb << GetSelected();

            Print( "Selected: " || selection );

      )

);

cb << Set( 2 );

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to initialize things in a modal window?

Place the message inside the window code. I guess that the code execution stops until a modal window is closed.

New Window( "Modal Example", << modal,

      cb = Combo Box(

            {"One", "Two", "Three"},

            selection = cb << GetSelected();

            Print( "Selected: " || selection );

      ), cb << Set( 2 )

);


View solution in original post

5 REPLIES 5
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to initialize things in a modal window?

Place the message inside the window code. I guess that the code execution stops until a modal window is closed.

New Window( "Modal Example", << modal,

      cb = Combo Box(

            {"One", "Two", "Three"},

            selection = cb << GetSelected();

            Print( "Selected: " || selection );

      ), cb << Set( 2 )

);


pmroz
Super User

Re: How to initialize things in a modal window?

Thanks MS that works great.  Dave sorry but your solution doesn't work.  When you put code inside a combobox definition, it only gets executed when you change a value in the combobox.

David_Burnham
Super User (Alumni)

Re: How to initialize things in a modal window?

Yes I see the problem now ... the method would still work for initialising the combo box but the script would need to be deferred until the user closes the window ... which for most cases is what we want for a modal window:

New Window( "Example", <<Modal,

  cb = Combo Box( {"One", "Two", "Three"}, <<Set(2)  )

);

selection = cb << GetSelected();

Print( "Selected: " || selection );

-Dave
David_Burnham
Super User (Alumni)

Re: How to initialize things in a modal window?

Or this:

New Window( "Example", <<Modal,

  cb = Combo Box(

             {"One", "Two", "Three"},

             <<Set Script( selection = cb << GetSelected(); Print( "Selected: " || selection );),

             <<Set(2)

         )

);

-Dave
David_Burnham
Super User (Alumni)

Re: How to initialize things in a modal window?

The clue is in the syntax used for the modal message itself, and in fact is generally true for display boxes independent of whether they are part of modal windows or not:  you can add messages to the display box itself:

     cb = ComboBox( mylist, <<Set(2) )

Dave

-Dave