BookmarkSubscribe
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 );

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User ms
Super User

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 )

);


0 Kudos
5 REPLIES 5
ms
Super User ms
Super User

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 )

);


0 Kudos
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.

0 Kudos
David_Burnham
Super User

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
0 Kudos
David_Burnham
Super User

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
0 Kudos
David_Burnham
Super User

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
0 Kudos