Subscribe Bookmark RSS Feed

Create a dynamic dialog box depending on user-selected choice from combo box

seburke89

Community Trekker

Joined:

Jun 4, 2015

Hi all,

I'm trying to create a dynamic, modal window based on some user selections from a combo box. If the user selects option 1 from the combo box, I'd like to have a number edit box appear for the user to enter in a value. If the user selects option 2 from the combo box, I'd like to have two number edit boxes appear for the user to fill out.

I've made numerous attempts at trying to get the number boxes to appear and/or change depending on the combo box selection with no luck. I have posted one such attempt below. Any help would be greatly appreciated!

Thanks.

new Window("test",

    modal,

    x=Combo Box({"1","2"},

        << set function(function({this},

            value = this << get;

            //print(value);

            return(value);

            );

        ),

    ),

    if(value == 3, H List Box(y = number edit box(.)));

    if(value == 4,    

        H List Box(

            y = number edit box(.),

            y2 = number edit box(.),

        )

    )   

);

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz

Super User

Joined:

Jun 23, 2011

Solution

This one's a little tricky.  I assume since "1" is the default that there will already be at least one number edit box.

new Window("test",

    << modal,

    x=Combo Box({"1","2"},

        value = x << get selected;

        if (value == "2",

            hlb << append(y2 = number edit box(.)),

            value == "1",

            y2 << delete;

        )

    ),

    hlb = H List Box(

        y1 = number edit box(.),

    ),

);

4 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Solution

This one's a little tricky.  I assume since "1" is the default that there will already be at least one number edit box.

new Window("test",

    << modal,

    x=Combo Box({"1","2"},

        value = x << get selected;

        if (value == "2",

            hlb << append(y2 = number edit box(.)),

            value == "1",

            y2 << delete;

        )

    ),

    hlb = H List Box(

        y1 = number edit box(.),

    ),

);

seburke89

Community Trekker

Joined:

Jun 4, 2015

Hi PMroz,

I listed the more complicated scenarios here - there could be other options in the combo boxes where there's no number edit boxes needed at all.

Thanks.

seburke89

Community Trekker

Joined:

Jun 4, 2015

Got a chance to play with this - this will work well - thanks so much!

melaniedrake

Staff

Joined:

May 30, 2014

The entire script needs to be within the combo box's function. Also, you have choices 1 and 2, but are comparing against a value of 3 or 4. Try this:

New Window( "test",

   <<modal,

   x = Combo Box( {"1", "2"},

      <<set function( Function( {this},

         value = this << get;

         If(

            value == 1,

            Try( (this << sib) << deletebox ); // delete what might already exist

            this << sibappend( H List Box( y = Number Edit Box( . ) ) );, // add new box

           

            value == 2,

            Try( (this << sib) << deletebox ); // delete what might already exist

            this << sibappend( // add new box

               H List Box(

                  y = Number Edit Box( . ),

                  y2 = Number Edit Box( . )

               )

            );

         );

       ) )

    ),

       H List Box( y = Number Edit Box( . ) ) // since 1 is selected by default, put the box here initially

);