cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
uday_guntupalli
Level VIII

Populating/Expand UI based on a selection

All, 
      I found this post and example very relevant to my needs. https://community.jmp.com/t5/Discussions/Creating-drop-down-menu-for-interactive-user-input/td-p/179.... However, as I try to implement/execute the code piece provided here, I don't see what I expected to happen. I think it is a typo, provided is my edited - working code. 

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

/* Extract a list of unique ages */

Summarize( a = By( :age ) );

Insert Into( a, "<Select Age>", 1 );

/* Create a modal dialog */

New Window( "Example",

    <<Modal,

    H List Box(

        /* Upon selecting an age, populate the second ComboBox with corresponding names */

        Panel Box( "Select an Age:",

            cb1 = Combo Box(

                a,

                <<SetFunction(

                    Function( {this},

                        selection = this << Get Selected();

                        r = dt << Get Rows Where( :age == Num( selection ) );

                        ageNames = :name[r];               ///////////////////////////////// EDIT - Needs to be :name[r] and not :name
 
                        Insert Into( ageNames, "<Select Name>", 1 );

                        cb2 << Set Items( ageNames );

                    )

                )

            )

        ),

        /* Print the selected values from both ComboBoxes in the log */

        Panel Box( "Select a Name:",

            cb2 = Combo Box(

                {"<Select Name>"},

                <<SetFunction(

                    Function( {this},

                        that=this<< Get Selected();

                        Print( selection, that  )

                    )

                )

            )

        )

    )

);

sel=num(selection)

 

Looking at the code and reading through it, I was hoping once the user selects an age in the first Combo Box, the second Combo Box should be populated with the names of people with that age. However, I don't see that happening here with the original code. This above code fixes it. 

image.png

 

Is this the best way to handle this - Or are there other options ? 

 

Best
Uday
2 REPLIES 2
txnelson
Super User

Re: Populating/Expand UI based on a selection

The "Modal" window is not letting the flow of your code work.  If you change the window to a non modal window the code works as you described you want it to work..  I have added to your script to make it work the way you want it, without it being a modal window.

Names Default To Here( 1 );
Clear Symbols();
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

/* Extract a list of unique ages */
Summarize( a = By( :age ) );
Insert Into( a, "<Select Age>", 1 );

/* Create a modal dialog */
nw = New Window( "Example", 
   // <<Modal,
	H List Box(

        /* Upon selecting an age, populate the second ComboBox with corresponding names */
		Panel Box( "Select an Age:", 

			cb1 = Combo Box(
				a,
				<<SetFunction(
					Function( {this},
						selection = this << Get Selected();
						r = dt << Get Rows Where( :age == Num( selection ) );
						ageNames = :name[r];               ///////////////////////////////// EDIT - Needs to be :name[r] and not :name 
						Insert Into( ageNames, "<Select Name>", 1 );
						cb2 << Set Items( ageNames );
					)
				)
			)
		), 

        /* Print the selected values from both ComboBoxes in the log */
		Panel Box( "Select a Name:",
			cb2 = Combo Box(
				{"<Select Name>"},
				<<SetFunction(
					Function( {this},
						that = this << Get Selected();
						Print( selection, that );
					)
				)
			)
		)
	),
	Button Box( "OK", nw << close window; myPGM )
);
myPGM = Expr( sel = Num( selection ) );
Jim
uday_guntupalli
Level VIII

Re: Populating/Expand UI based on a selection

@txnelson
       Hello Jim, 

             I could get the code sample from the other discussion  to work even  whille the window is Modal. The issue was in the original discussion, the code is not subsetting the selecting rows, which I added. However, I am wondering if this is the best way to do this or are there any better solutions ? 

 

 

Best
Uday