Focal Point
Multi-select Listbox on the fly.

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2111002292

July 20, 2008, 07:20 AM
Anatess
Multi-select Listbox on the fly.
Hi All -

Another multi-select listbox question...
I have the sample code below. The code creates a multi-select listbox on the fly and then keeps the selected value highlighted after the form is submitted and a new session starts. If you select just one country, it works just fine. But, when more than one country is selected, the code uses the DEFAULT value instead of the values in the listbox (should be each value separated by OR). What am I doing wrong?

-* File testcar.fex
-DEFAULT &CNTRYSEL='JAPAN';
-SET &ECHO=ALL
DEFINE FILE CAR
CNTRYCHECK/A256=IF &CNTRYSEL.QUOTEDSTRING EQ GETTOK(&CNTRYSEL.QUOTEDSTRING,ARGLEN(256,&CNTRYSEL.QUOTEDSTRING,'I3'),-1,' OR ',10,'A10') THEN
                   ':'|&CNTRYSEL.QUOTEDSTRING||':'; ELSE
				   STRREP(256,&CNTRYSEL.QUOTEDSTRING,1,'''',1,':',256,CNTRYCHECK);
CNTRY/A22=':'|COUNTRY||':';
END
TABLE FILE CAR
SUM
COMPUTE PICKED/A8=IF CNTRYCHECK CONTAINS CNTRY THEN 'selected' ELSE ' '; NOPRINT
COMPUTE SELECT/A300='<option VALUE='|COUNTRY||' '|PICKED||' displaytext='''|COUNTRY||'''>'|COUNTRY||'</option>';
BY COUNTRY NOPRINT
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS OPTIONS FORMAT ALPHA
END
-*
TABLE FILE OPTIONS
PRINT SELECT
ON TABLE HOLD AS OPTLINES FORMAT ALPHA
END
-RUN
-SET &PICKALL=IF '&CNTRYSEL.EVAL' EQ '$*' THEN 'selected' ELSE ' ';

TABLE FILE CAR
HEADING
" COUNTRY picked is &CNTRYSEL "
PRINT
   CAR
BY COUNTRY
WHERE COUNTRY EQ '&CNTRYSEL' ;
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SET ASNAMES ON
ON TABLE HOLD AS RPT1 FORMAT HTMTABLE
END
-RUN

-HTMLFORM BEGIN

<html>
<head>
<br />
!IBI.FIL.RPT1;
<br />
<form name='form1' method='POST' action='/ibi_apps/WFServlet?' target='_self'
 style='font-family: Arial; font-size: 8pt; word-spacing: 0; margin-top: 0; margin-bottom: 0; height:100%'>
<input type="hidden" name="IBIF_ex" value="testcar">

<p style='margin-top: 0; margin-bottom: 0'><b>Country</b></p>
<p style='margin-top: 0; margin-bottom: 0'><select id=listbox1 size=5 multiple name='CNTRYSEL' operation='OR'>
<option value='$*' &PICKALL.EVAL displaytext='All'>All</option>
!IBI.FIL.OPTLINES;
</select></p>
<br />
<p style='margin-top: 0; margin-bottom: 0'><input type='submit' value='Submit'  name='form1submit'></p>
</form>

</body>

</html>

-HTMLFORM END
-EXIT


I'm on 7.1.3. Thanks!


WF 8.1.05 Windows
July 20, 2008, 12:30 PM
j.gross
When I ran it, and peeked at View Source, I found:
0 ERROR AT OR NEAR LINE      7  IN PROCEDURE ADHOCRQ FOCEXEC *
  (FOC252) COMPUTATIONAL EXPRESSION NOT RECOGNIZED: ELSE
  STRREP(256,'JAPAN',1,'''',1,':',256,CNTRYCHECK)


There is a stray semicolon in the THEN clause of your define.


- Jack Gross
WF through 8.1.05
July 20, 2008, 12:39 PM
j.gross
The delimiter for GETTOK is a single character, so the call in your example uses Space as the delimiter.

Also, it appears that what you are attempting to calculate could be done in a -SET, and then referenced in the define as a simple quoted string.


- Jack Gross
WF through 8.1.05
July 20, 2008, 01:03 PM
Alan B
The operation='OR' is specific to HTML painter generated pages and IB javascript control.

What you get back from plain HTML is &CNTRYSEL for a single item or &CNTRYSEL0 and &CNTRYSEL1,&CNTRYSEL2 etc. for multiple selects. You can deal with this in WF, and there are some examples here, or in javascript, whichever you prefer.


Alan.
WF 7.705/8.007
July 20, 2008, 01:10 PM
j.gross
Your logic will not work, because on drilldown where multiple entries are selected the variable you are testing reflects only the first.

For example, when I select England, France and Italy, &CNTRYSEL contains just ENGLAND:
&CNTRYSEL = ENGLAND <--
&CNTRYSEL0 = 3
&CNTRYSEL1 = ENGLAND
&CNTRYSEL2 = FRANCE
&CNTRYSEL3 = ITALY

When WF generates a dynamic menu for autoprompting, it includes Javascript to sense the "operation='OR'" attribute and string the selections together. -- But without that JS infrastructure you just get the classic handling of multiple selections, returning the first (in the bare & var), a counter (with suffix 0), and the individual values (suffix 1,2...)

Unless you can piggyback IBI's JS, you'll have to handles the &vars in the classic manner (sensing existence of &CNTRYSEL0, if present looping thru the list of values, else using &CNTRYSEL's value)


- Jack Gross
WF through 8.1.05
July 20, 2008, 11:08 PM
Waz
quote:
sensing existence of &CNTRYSEL0

My suggestion is don't sense anything, make sure its there.
-DEFAULT &CNTRYSEL0 = 1 ;
-DEFAULT &CNTRYSEL1 = '&COUNTRYSEL.EVAL';

Also if you need to filter on these, I would suggest writing them to a file and either joining to it or us WHERE IN FILE


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

July 21, 2008, 05:15 AM
Anatess
Whoa. Is the 0,1,2,etc variables also created when using HTML Layout Painter? Because, I've used several multi-select listboxes via the painter and &var always contains 'this' or 'that' or 'the other'. So, I went ahead and modified my sample code just to try out the numbered vars and, by golly, it works! I had to build the where clause though. Here's the fex that works:
-* File testcar.fex
-DEFAULT &CNTRYSEL='$*';
-DEFAULT &ORSEL='';
-DEFAULT &CNTRYSEL0=0;
-DEFAULT &CNTRYSEL1='';
-SET &ECHO=ALL
TABLE FILE CAR
SUM
-IF &CNTRYSEL0 NE 0 THEN GOTO NEXT005;
-SET &ORSEL=''''||'&CNTRYSEL.EVAL'||'''';
COMPUTE PICKED/A8=IF COUNTRY EQ '&CNTRYSEL.EVAL' THEN 'selected' ELSE '        ';
-GOTO NEXT005E
-NEXT005
COMPUTE PICKED/A8=
-SET &KNT=0;
-REPEAT :LOOP010 &CNTRYSEL0 TIMES;
-SET &KNT=&KNT+1;
-IF &KNT EQ 1 THEN GOTO NEXT010;
-SET &ORSEL=&ORSEL | ' OR ''' | &CNTRYSEL&KNT.EVAL | '''';
ELSE IF COUNTRY EQ '&CNTRYSEL.&KNT' THEN 'selected'
-GOTO NEXT010E
-NEXT010
-SET &ORSEL=''''|'&CNTRYSEL1.EVAL'|'''';
IF COUNTRY EQ '&CNTRYSEL1.EVAL' THEN 'selected'
-NEXT010E
-TYPE &ORSEL
-:LOOP010
ELSE '        ';
-NEXT005E
COMPUTE SELECT/A300='<option VALUE='''||COUNTRY||''' '|PICKED||' displaytext='''||COUNTRY||'''>'||COUNTRY||'</option>';
BY COUNTRY NOPRINT
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS OPTIONS FORMAT ALPHA
END
-*
TABLE FILE OPTIONS
PRINT SELECT
ON TABLE HOLD AS OPTLINES FORMAT ALPHA
END
-RUN
-IF &CNTRYSEL0 EQ 0 THEN GOTO NEXT015;
-SET &PICKALL=IF '&CNTRYSEL1.EVAL' EQ '$*' THEN 'selected' ELSE ' ';
-GOTO NEXT015E
-NEXT015
-SET &PICKALL=IF '&CNTRYSEL.EVAL' EQ '$*' THEN 'selected' ELSE ' ';
-NEXT015E

TABLE FILE CAR
HEADING
" COUNTRY picked is &ORSEL "
PRINT
   CAR
BY COUNTRY
WHERE COUNTRY EQ &ORSEL ;
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SET ASNAMES ON
ON TABLE HOLD AS RPT1 FORMAT HTMTABLE
END
-RUN

-HTMLFORM BEGIN

<html>
<head>
<br />
!IBI.FIL.RPT1;
<br />
<form name='form1' method='POST' action='/ibi_apps/WFServlet?' target='_self'
 style='font-family: Arial; font-size: 8pt; word-spacing: 0; margin-top: 0; margin-bottom: 0; height:100%'>
<input type="hidden" name="IBIF_ex" value="testcar">

<p style='margin-top: 0; margin-bottom: 0'><b>Country</b></p>
<p style='margin-top: 0; margin-bottom: 0'><select id=listbox1 size=5 multiple name='CNTRYSEL' operation='OR'>
<option value='$*' &PICKALL.EVAL displaytext='All'>All</option>
!IBI.FIL.OPTLINES;
</select></p>
<br />
<p style='margin-top: 0; margin-bottom: 0'><input type='submit' value='Submit'  name='form1submit'></p>
</form>

</body>

</html>

-HTMLFORM END
-EXIT


Thank you guys!
Not important P.S. Anybody tried running a Focus report on an iPhone? They got all these apps for my phone now - I even got iPint where I can drink virtual beer. And I can make my phone a lightsaber with awesome sound effects. Or play Texas Hold 'Em Poker. Would be really awesome to get reports running on this thingamagig!


WF 8.1.05 Windows
July 21, 2008, 09:29 AM
Alan B
iPhone will display standard reports, no problem. Not sure about MRE and other proprietary WF stuff. The js can be an issue on non IE/Firefox browser, though getting better.

Look for Mobile Maintain though. That should be excellent.


Alan.
WF 7.705/8.007
July 21, 2008, 09:43 AM
Tony A
Also check out the Mobile Favorites as presented at Summit.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
July 21, 2008, 10:01 AM
Francis Mariani
quote:
virtual beer
just got a really empty feeling in my belly...

I've been trying to procure an iPhone for the last week here in Toronto with no luck.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server