cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
ALopez
Level III

How to apply "Max Selected" to a check box list

Hi, Is it possible to apply the "Max Selected" filter to limit the number of Check Boxes that a User can select?

I will appreciate your suggestions.

Names Default To Here( 1 );
New Window( "Example",
	cb = Check Box(
		{"One", "Two", "Three"}, Max Selected(2),
		Print(
			"Selected: " ||
			Concat Items( cb << Get Selected(), ", " )
		)
	)
);
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to apply "Max Selected" to a check box list

There is not a Max Selected message that can be set, however one can write a script to do it.  Here is my way of handling it

Names Default To Here( 1 );
New Window( "Example",
	cb = Check Box(
		{"One", "Two", "Three"},
		curSelected = cb << get selected;
		If( N Items( curSelected ) > 2, 
			// Determine the one just selected
			For( i = 1, i <= N Items( cb << get items ), i++,
				If(
					Contains( curSelected, (cb << get items)[i] ) > 0 & 
						Contains( prevSelected, (cb << get items)[i] ) == 0,
						dialog("Too many selections");
						cb << set(i,0);
						Break();
				)
			);
		,
			prevSelected = curSelected;
		);
	)
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to apply "Max Selected" to a check box list

There is not a Max Selected message that can be set, however one can write a script to do it.  Here is my way of handling it

Names Default To Here( 1 );
New Window( "Example",
	cb = Check Box(
		{"One", "Two", "Three"},
		curSelected = cb << get selected;
		If( N Items( curSelected ) > 2, 
			// Determine the one just selected
			For( i = 1, i <= N Items( cb << get items ), i++,
				If(
					Contains( curSelected, (cb << get items)[i] ) > 0 & 
						Contains( prevSelected, (cb << get items)[i] ) == 0,
						dialog("Too many selections");
						cb << set(i,0);
						Break();
				)
			);
		,
			prevSelected = curSelected;
		);
	)
);
Jim
ALopez
Level III

Re: How to apply "Max Selected" to a check box list

Thanks @txnelson, I was afraid that the answer was going to be: No. Very nice your work-around, I will try to implement it in my code.

txnelson
Super User

Re: How to apply "Max Selected" to a check box list

All you need to do for such items as your "Max Selected" message you suggested, is to go to the Scripting Index and look at the CheckBox entry.  And if you don't see a message that will do what you are suggesting, then there isn't such a capability directly from the object

Jim