cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Georgios_Tsim
Level III

Dynamic Number boxes based on list items

In the following script I have a list of 3 elements and I am trying to create a new window where the user can enter some values for each of the elements:

myList = {"apple", "banana", "orange"};

nw = New Window( "Enter Numbers",
    <<Modal,
    <<Return Result,
    V List Box(
		Text Box("Enter the values"),
        For( i = 1, i <= N Items( myList ), i++,
            Lineup Box( Text Box( Eval(myList[i])),
                Number Edit Box( 42 )
            )
        ),
        H List Box(
            Button Box( "OK" ),
            Button Box( "Cancel" )
        )
    )
);

I use the for loop because the number of the items in the list "myList" changes. So that I would like to happen also for the Number Edit Boxes. However, I get back the following:

Georgios_Tsim_0-1724768252918.png

Ideally I would like the values that the end user enters to be saved in a list.

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Dynamic Number boxes based on list items

Here is the approach that I would take

Names Default To Here( 1 );
myList = {"apple", "banana", "orange"};

myVList = V List Box(
	Text Box( "Enter the values" ),
	lub = Lineup Box( N Col( 2 ), ),
	H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )
);
For Each( {box}, myList,
	lub << append( Text Box( Eval( box ) ) );
	lub << append( Number Edit Box( 42 ) );
);
	
nw = New Window( "Enter Numbers",
	<<Modal,
	<<Return Result,
	myVlist
);

txnelson_0-1724769101857.png

 

Jim

View solution in original post

jthi
Super User

Re: Dynamic Number boxes based on list items

Multiple different ways how you can do this.

 

You can use different methods of collecting the results, you can use XPath

 

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

value_collector = V List Box(
	Text Box("Enter the values"),
	lub = Lineup Box(N Col(2))
);

For Each({fruit}, fruits,
	lub << append(Text Box(fruit));
	lub << append(Number Edit Box(42));
);

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		value_collector,
		H List Box(
			Button Box("OK",
				vals = (lub << XPath("//NumberEditBox")) << get;
			), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

Show(fruits, vals);

or store the references to a list

 

 

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

value_collector = V List Box(
	Text Box("Enter the values"),
	lub = Lineup Box(N Col(2))
);

nebs = {};
For Each({fruit}, fruits,
	lub << append(Text Box(fruit));
	lub << append(neb = Number Edit Box(42));
	Insert Into(nebs, neb);
);

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		value_collector,
		H List Box(
			Button Box("OK",
				vals = nebs << get;
			), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

Show(fruits, vals);

or associative array

 

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

value_collector = V List Box(
	Text Box("Enter the values"),
	lub = Lineup Box(N Col(2))
);

vals = Associative Array();
For Each({fruit}, fruits,
	lub << append(Text Box(fruit));
	lub << append(neb = Number Edit Box(42));
	vals[fruit] = neb;
);

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		value_collector,
		H List Box(
			Button Box("OK",
				res = Associative Array(vals << get keys, (vals << get values) << get);
			), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

Show(fruits, vals, res);

With these you will have UI something like this

jthi_1-1724770118276.png

Or you could utilize totally different display box elements (table box and number col edit box)

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		Text Box("Enter the values:"),
		Table Box(
			String Col Box("Fruit", fruits),
			nceb = Number Col Edit Box("Value", J(N Items(fruits), 1, 42)),
		),
		H List Box(
			Button Box("OK"), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

show(nw["nceb"]);

jthi_0-1724770072443.png

 

-Jarmo

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Dynamic Number boxes based on list items

Here is the approach that I would take

Names Default To Here( 1 );
myList = {"apple", "banana", "orange"};

myVList = V List Box(
	Text Box( "Enter the values" ),
	lub = Lineup Box( N Col( 2 ), ),
	H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )
);
For Each( {box}, myList,
	lub << append( Text Box( Eval( box ) ) );
	lub << append( Number Edit Box( 42 ) );
);
	
nw = New Window( "Enter Numbers",
	<<Modal,
	<<Return Result,
	myVlist
);

txnelson_0-1724769101857.png

 

Jim
jthi
Super User

Re: Dynamic Number boxes based on list items

Multiple different ways how you can do this.

 

You can use different methods of collecting the results, you can use XPath

 

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

value_collector = V List Box(
	Text Box("Enter the values"),
	lub = Lineup Box(N Col(2))
);

For Each({fruit}, fruits,
	lub << append(Text Box(fruit));
	lub << append(Number Edit Box(42));
);

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		value_collector,
		H List Box(
			Button Box("OK",
				vals = (lub << XPath("//NumberEditBox")) << get;
			), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

Show(fruits, vals);

or store the references to a list

 

 

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

value_collector = V List Box(
	Text Box("Enter the values"),
	lub = Lineup Box(N Col(2))
);

nebs = {};
For Each({fruit}, fruits,
	lub << append(Text Box(fruit));
	lub << append(neb = Number Edit Box(42));
	Insert Into(nebs, neb);
);

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		value_collector,
		H List Box(
			Button Box("OK",
				vals = nebs << get;
			), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

Show(fruits, vals);

or associative array

 

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

value_collector = V List Box(
	Text Box("Enter the values"),
	lub = Lineup Box(N Col(2))
);

vals = Associative Array();
For Each({fruit}, fruits,
	lub << append(Text Box(fruit));
	lub << append(neb = Number Edit Box(42));
	vals[fruit] = neb;
);

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		value_collector,
		H List Box(
			Button Box("OK",
				res = Associative Array(vals << get keys, (vals << get values) << get);
			), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

Show(fruits, vals, res);

With these you will have UI something like this

jthi_1-1724770118276.png

Or you could utilize totally different display box elements (table box and number col edit box)

Names Default To Here(1);

fruits = {"apple", "banana", "orange"};

nw = New Window("Enter Numbers", <<Modal, <<Return Result, 
	V List Box(
		Text Box("Enter the values:"),
		Table Box(
			String Col Box("Fruit", fruits),
			nceb = Number Col Edit Box("Value", J(N Items(fruits), 1, 42)),
		),
		H List Box(
			Button Box("OK"), 
			Button Box("Cancel")
		)
	)
);

If(nw["Button"] != 1,
	Throw("Cancelled")
);

show(nw["nceb"]);

jthi_0-1724770072443.png

 

-Jarmo