<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I create a modal selection window with multiple selection in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/802850#M97952</link>
    <description>&lt;P&gt;Hello JMP community,&lt;/P&gt;&lt;P&gt;I need some help with the following: I have a table (&lt;FONT face="courier new,courier"&gt;dt&lt;/FONT&gt;) with a nominal numeric column (&lt;FONT face="courier new,courier"&gt;Values&lt;/FONT&gt;). I would like to create a window that displays the sorted unique values of the &lt;FONT face="courier new,courier"&gt;Values&lt;/FONT&gt; column. Then I would like to select one or multiple values return those and pass them to a &lt;FONT face="courier new,courier"&gt;Select Where&lt;/FONT&gt; function.&lt;/P&gt;&lt;P&gt;I am absolutely a beginner at JSL and your help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To solve this issue, I created a function &lt;FONT face="courier new,courier"&gt;SelectNumericValues&lt;/FONT&gt; as follows:&lt;/P&gt;&lt;PRE&gt;// function to create a modal window with selection functionality&lt;BR /&gt;SelectNumericValues = Function( {dt, column_name}, 
    // Use Summarize to find unique values in the specified column
    Summarize( unique_values = By( Column( dt, column_name ) ) );
    // Calculate the maximum number of selections
    max_selections = N Items( unique_values );

    // Create a window for user selection
	nw = New Window( "Select Values",
		&amp;lt;&amp;lt;Modal,
		&amp;lt;&amp;lt;Return Result,
		V List Box(
			Text Box( "Select values for analysis:" ),
			lb = List Box( unique_values, Max Selected( max_selections ) ),
			H List Box(
				Button Box( "OK",
					selected_values = lb &amp;lt;&amp;lt; Get Selected;
				//nw &amp;lt;&amp;lt; Close Window;
				),
				Button Box( "Cancel",
					selected_values = {};
					nw &amp;lt;&amp;lt; Close Window;
				)
			)
		)
	);

    // Wait for user input
	selected_values = nw &amp;lt;&amp;lt; Show Window;

    // Return the selected values
	selected_values;
);&lt;BR /&gt;&lt;BR /&gt;// call my function with table dt and nominal numeric column "Values"&lt;BR /&gt;selected_values = SelectNumericValues(dt, "Values");&lt;BR /&gt;&lt;BR /&gt;dt_select = dt &amp;lt;&amp;lt; Select Where( :Values == selected_values)&lt;/PRE&gt;&lt;P&gt;The window with the unique sorted values is correctly rendered:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="paul_vanoppen_0-1727737764372.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/68739iA3789E7A48A23A36/image-size/medium?v=v2&amp;amp;px=400" role="button" title="paul_vanoppen_0-1727737764372.png" alt="paul_vanoppen_0-1727737764372.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I can select one or multiple options. But I end up with these two errors:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;Send Expects Scriptable Object in access or evaluation of 'List' , {/*###*/"0", "1", "2"}&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;Name Unresolved: Button in access or evaluation of 'Button' , Button( 1 ) /*###*/&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Which suggest that I am not handling the buttons correctly in the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;SelectNumericValues&lt;/FONT&gt; function and that I am also incorrectly dealing with the returned values in the &lt;FONT face="courier new,courier"&gt;Select Where&lt;/FONT&gt; function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="paul_vanoppen_1-1727737820740.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/68740iF18B5402325CD0DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="paul_vanoppen_1-1727737820740.png" alt="paul_vanoppen_1-1727737820740.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an additional question: how would I implement the requirement that at least one option should be selected (closing the modal window with none selected should either not be possible, or it would implicitly mean that all options are selected).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Paul&lt;/P&gt;</description>
    <pubDate>Mon, 30 Sep 2024 23:18:19 GMT</pubDate>
    <dc:creator>paul_vanoppen</dc:creator>
    <dc:date>2024-09-30T23:18:19Z</dc:date>
    <item>
      <title>How do I create a modal selection window with multiple selection</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/802850#M97952</link>
      <description>&lt;P&gt;Hello JMP community,&lt;/P&gt;&lt;P&gt;I need some help with the following: I have a table (&lt;FONT face="courier new,courier"&gt;dt&lt;/FONT&gt;) with a nominal numeric column (&lt;FONT face="courier new,courier"&gt;Values&lt;/FONT&gt;). I would like to create a window that displays the sorted unique values of the &lt;FONT face="courier new,courier"&gt;Values&lt;/FONT&gt; column. Then I would like to select one or multiple values return those and pass them to a &lt;FONT face="courier new,courier"&gt;Select Where&lt;/FONT&gt; function.&lt;/P&gt;&lt;P&gt;I am absolutely a beginner at JSL and your help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To solve this issue, I created a function &lt;FONT face="courier new,courier"&gt;SelectNumericValues&lt;/FONT&gt; as follows:&lt;/P&gt;&lt;PRE&gt;// function to create a modal window with selection functionality&lt;BR /&gt;SelectNumericValues = Function( {dt, column_name}, 
    // Use Summarize to find unique values in the specified column
    Summarize( unique_values = By( Column( dt, column_name ) ) );
    // Calculate the maximum number of selections
    max_selections = N Items( unique_values );

    // Create a window for user selection
	nw = New Window( "Select Values",
		&amp;lt;&amp;lt;Modal,
		&amp;lt;&amp;lt;Return Result,
		V List Box(
			Text Box( "Select values for analysis:" ),
			lb = List Box( unique_values, Max Selected( max_selections ) ),
			H List Box(
				Button Box( "OK",
					selected_values = lb &amp;lt;&amp;lt; Get Selected;
				//nw &amp;lt;&amp;lt; Close Window;
				),
				Button Box( "Cancel",
					selected_values = {};
					nw &amp;lt;&amp;lt; Close Window;
				)
			)
		)
	);

    // Wait for user input
	selected_values = nw &amp;lt;&amp;lt; Show Window;

    // Return the selected values
	selected_values;
);&lt;BR /&gt;&lt;BR /&gt;// call my function with table dt and nominal numeric column "Values"&lt;BR /&gt;selected_values = SelectNumericValues(dt, "Values");&lt;BR /&gt;&lt;BR /&gt;dt_select = dt &amp;lt;&amp;lt; Select Where( :Values == selected_values)&lt;/PRE&gt;&lt;P&gt;The window with the unique sorted values is correctly rendered:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="paul_vanoppen_0-1727737764372.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/68739iA3789E7A48A23A36/image-size/medium?v=v2&amp;amp;px=400" role="button" title="paul_vanoppen_0-1727737764372.png" alt="paul_vanoppen_0-1727737764372.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I can select one or multiple options. But I end up with these two errors:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;Send Expects Scriptable Object in access or evaluation of 'List' , {/*###*/"0", "1", "2"}&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;Name Unresolved: Button in access or evaluation of 'Button' , Button( 1 ) /*###*/&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Which suggest that I am not handling the buttons correctly in the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;SelectNumericValues&lt;/FONT&gt; function and that I am also incorrectly dealing with the returned values in the &lt;FONT face="courier new,courier"&gt;Select Where&lt;/FONT&gt; function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="paul_vanoppen_1-1727737820740.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/68740iF18B5402325CD0DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="paul_vanoppen_1-1727737820740.png" alt="paul_vanoppen_1-1727737820740.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an additional question: how would I implement the requirement that at least one option should be selected (closing the modal window with none selected should either not be possible, or it would implicitly mean that all options are selected).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Paul&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 23:18:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/802850#M97952</guid>
      <dc:creator>paul_vanoppen</dc:creator>
      <dc:date>2024-09-30T23:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a modal selection window with multiple selection</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/802881#M97955</link>
      <description>&lt;P&gt;I found a working solution. I made the following mistakes:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;the function&amp;nbsp;&lt;FONT face="courier new,courier"&gt;SelectNumericValues&lt;/FONT&gt; returns a list of characters, not of numbers.&lt;/LI&gt;&lt;LI&gt;the &lt;FONT face="courier new,courier"&gt;Select Where&lt;/FONT&gt; function call requires the function Contains to match the list of numbers.&lt;/LI&gt;&lt;LI&gt;This line&amp;nbsp;&lt;FONT face="courier new,courier"&gt;selected_values = nw &amp;lt;&amp;lt; Show Window;&lt;/FONT&gt; in the &lt;FONT face="courier new,courier"&gt;SelectNumericValues&lt;/FONT&gt;&amp;nbsp;function causes the button related error (I think)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;As a result, I need to coerce the selected values to numeric. And I need to adjust the &lt;FONT face="courier new,courier"&gt;Select Where&lt;/FONT&gt; function call.&lt;/P&gt;&lt;P&gt;I find that this works correctly:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;// Function to generate the user selection window for numeric values
SelectNumericValues = Function( {dt, column_name}, 
   // Use Summarize to find unique values in the specified column
	Summarize( unique_values = By( Column( dt, column_name ) ) );
    // Calculate the maximum number of selections
	max_selections = N Items( unique_values );

    // Create a window for user selection
	nw = New Window( "Select Values",
		&amp;lt;&amp;lt;Modal,
		&amp;lt;&amp;lt;Return Result,
		V List Box(
			Text Box( "Select values for analysis:" ),
			lb = List Box( unique_values, Max Selected( max_selections ) ),
			H List Box(
				Button Box( "OK",
					selected_values = lb &amp;lt;&amp;lt; Get Selected;
					// Convert selected values to numeric
					For( i = 1, i &amp;lt;= N Items( selected_values ), i += 1,
						selected_values[i] = Num( selected_values[i] )
					);
				),
				Button Box( "Cancel",
					selected_values = {};
					nw &amp;lt;&amp;lt; Close Window;
				)
			)
		)
	);

	// Return the selected values
	selected_values;
);

selected_values = SelectNumericValues(dt, "Values");
dt &amp;lt;&amp;lt; Select Where( Contains( selected_values, :Values) );&lt;/PRE&gt;&lt;P&gt;I am happy to see additional improvements from other users.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 01:31:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/802881#M97955</guid>
      <dc:creator>paul_vanoppen</dc:creator>
      <dc:date>2024-10-01T01:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a modal selection window with multiple selection</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/802882#M97956</link>
      <description>&lt;P&gt;I think you need to look into using a Data Filter.&amp;nbsp; It will do the display and the selection for you.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 01:59:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/802882#M97956</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-10-01T01:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a modal selection window with multiple selection</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/803128#M97988</link>
      <description>&lt;P&gt;Thanks Jim!&lt;/P&gt;&lt;P&gt;Based on your recommendation I created a script using the Data Filter function. Thanks for pointing me to it as it is a very useful function for interactive filtering of data.&lt;/P&gt;&lt;P&gt;The main functionality that my script is implementing is to create output (a journal, saved e.g. as a pdf document) based on the data after it is filtered by the user. In other words, there is no need here for any interactive, multi-variate, filtering. In that sense, the approach I have shared in this post is useful to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 02:26:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-modal-selection-window-with-multiple-selection/m-p/803128#M97988</guid>
      <dc:creator>paul_vanoppen</dc:creator>
      <dc:date>2024-10-02T02:26:44Z</dc:date>
    </item>
  </channel>
</rss>

