Subscribe Bookmark RSS Feed

How to initialize things in a modal window?

pmroz

Super User

Joined:

Jun 23, 2011

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
Solution

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 )

);


5 REPLIES
Solution

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

Joined:

Jun 23, 2011

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

Joined:

Jul 13, 2011

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

Joined:

Jul 13, 2011

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

Joined:

Jul 13, 2011

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