Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Dynamic dropdowns - default selection?
Go
New
Search
Notify
Tools
Reply
  
[CLOSED] Dynamic dropdowns - default selection?
 Login/Join
 
Gold member
posted
Greetings,

At our institution, we create launch pages via HTML Layout Manager which have drop-down parameters bound to executing dynamic procedures to populate the name/values in the drop-down. The dynamic procedures execute code that returns these name/value pairs in XML.

Is there any way in the XML output from these dynamic procedures to "tag" the default selected value to be displayed to the user? As it currently works, the default value is the first value in the returned procedure. The HTML standard allows for drop-downs to have a
"SELECTED" attribute in the
 
Posts: 63 | Registered: March 07, 2006Reply With QuoteReport This Post
Guru
posted Hide Post
Dan,

The first thing I would try is have the first item in your list be the one as default. It does sound like you don't want to change the order.

The next thing I would do it to use javascript to select the one you want in the in list from the onload form action. I suspect this will lead to your list come back with the first and not your default selected and then chaining happening. Then your javascript will happen and chaining again. In other words things will get slower.

Fernando


Prod WF 8.1.04, QA WF 8.2.03, Dev WF 8.2.03
 
Posts: 277 | Registered: October 10, 2006Reply With QuoteReport This Post
Gold member
posted Hide Post
Thanks Fernando for the suggestions.

I'm not sure how I would latch onto the output from a dynamic parameter load using a javascript onload form action, since this is coming from IBI's HTML Layout Manager-supplied code generater.

I was hoping instead to do this from the dynamic procedure FEX that is being called. What we're trying to do is return a drop down list of semesters (FAll 2009, Spring 2009, etc) for the user to select. We have an upper bound on the list (2009), but we'd like to set the default selection to be the current term (Fall 2007). In standard HTML, it would be

<OPTION selected>Fall 2007</OPTION>  

It's very simple to do this using a standard server-side scripting language like PHP or ASP. But within the HTML Layout Manager GUI tool, we select the drop down parameter to be DYNAMIC against an external PROCEDURE, then write the server-side procedure as a FEX returning XML with name/value pairs. If we could just tag the appropriate name/value pair to be "selected", then it would be great. Unfortunately, I can't find documentation on the API for the code generated from dynamic procedure parameter bindings using the HTML Layout Manager GUI tool.

One would think we shouldn't have to go to javascript to query the form to inject a "selected" attribute on the form. This would mean we'd have to maintain two sets of logic for terms, one in an external FEX and one in a javascript for the default term.

It shouldn't be this difficult (my naivete)....

-- Dan

Prod: WF 7.6.2 Linux BID/MRE/DM -- Test: same
 
Posts: 63 | Registered: March 07, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
Dan,

As you have mentioned, if you use the internal method of populating the combos via a fex, you should have the output held as XML. A function within the ibirls2.js module parses this XML feed and dynamically creates the OPTION tags so there is no comprehnsion of a selected value, it doesn't add one at all.

Short of coding your own js module to handle this, I am fairly sure that there is nothing existing in ibirls that will allow you to do this.

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 
 
Posts: 5687 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
Guru
posted Hide Post
Dan,

In the HTML you will find something like this:



change it to:



Then inside the create

<script>
function MyLoad() {
// Needed to get your data
UpdateData();
var obj = document.getElementById('object id of your drop down list');
i = line number you want selected
// multi select
obj.options[i].selected = true;
// or if single select
obj.options.selectedIndex = i;
}



Hope this helps,

Fernando


Prod WF 8.1.04, QA WF 8.2.03, Dev WF 8.2.03
 
Posts: 277 | Registered: October 10, 2006Reply With QuoteReport This Post
Guru
posted Hide Post
Fernando,

The problem with your solution is the UpdateData() function calls the WebFOCUS to gather the data and the finishes, allowing the next javascript command to run. If the data gathering takes a little time then the commands to set the value of the list will run before the list gets populated.

I've been looking at a way to delay the running of commands until the data has been returned, but have not met with any success as yet. It seems that UpdateData() returns regardless off whether the data has finished uploading or not.

Cheers

Stuart
 
Posts: 253 | Location: Melbourne, Australia | Registered: February 07, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Stuart

You are correct. IE will carry on before the UpdateData has completed. Firefox won't, which is one of the annoying differences between browsers.

To overcome this, and using Fernando's code as a basis:
function MyLoad() {
// Needed to get your data
UpdateData();
setDefault();
}
function setDefault() {
var obj = document.getElementById('object id of your drop down list');
if (obj.innerHTML!=''){
i = line number you want selected
// multi select
obj.options[i].selected = true;
// or if single select
obj.options.selectedIndex = i;
} else {
setTimeout("setDefault()",100);
}

Firefox accepts this, and will never use the setTimeout, IE will use the setTimeout and check to see if data (the innerHTML) has been returned. If not it will rerun in 100 milliseconds, else set selectedIndex.

If you wanted this to be dynamic, then in the fex, you can set the item you want selected to have, say, an asterisk concatenated, then search through the options for the asterisk set the selectedIndex to that option and replace the * with null in the text and value. If this is wanted, I, or someone else here, can get the code together for it. It is relatively easy.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Guru
posted Hide Post
Alan,

setTimeout() is exactly what was needed to make things work. I'd been playing around with for and while loops, but it kept displaying messages that the script was taking too long to finish.

I need it to be a little dynamic - the same value needs to be set, but the place in the list may vary. Here is the code I use to walk through the list and set the desired value:
function MyLoad() {
//Needed to get your data
UpdateData();
setDefault('Value you want to set');
}

function setDefault(myVal) {
var obj = document.getElementById('object id of your drop down list');
if (obj.innerHTML!=''){
	for(i=0;i<obj.length;i++) {
		if (obj.options[i].value == myVal) {
			obj.options[i].selected = true;
		}
	}
} else {
	setTimeout("setDefault('" + myVal + "')",100);
}
}


Thanks again for your help

Stuart


WebFOCUS 8.2.03 (8.2.06 in testing)
 
Posts: 253 | Location: Melbourne, Australia | Registered: February 07, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Glad it works for you Stuart.
Just on a point of efficiency, you may want to add a break after finding the correct value to stop processing:
.
function setDefault(myVal) {
var obj = document.getElementById('object id of your drop down list');
if (obj.innerHTML!=''){
	for(i=0;i<obj.length;i++) {
		if (obj.options[i].value == myVal) {
			obj.options[i].selected = true;
                        break
		}
	}
} else {
	setTimeout("setDefault('" + myVal + "')",100);
}
}


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Guru
posted Hide Post
Dan,

You are correct in saying that UpdateData has issues. The solutions from Alan and Stuart will work. I have another solution that is very general and can be used in many ways.

My example uses a select, but any object will do. Create a select object. You can chain it or not.

<SELECT language=javascript id=listbox5 style="Z-INDEX: 74; LEFT: 735px; VISIBILITY: hidden; WIDTH: 325px; POSITION: absolute; TOP: 255px; HEIGHT: 135px" tabIndex=30 multiple size=3 name=listbox4 operation="OR" newchainnumber="0" chainnumber="0" inchainindex="5" cacheruntimedata="0" sourcetype="typeFex" datafieldtype="CHAR" datatype="-1" datasource="app/hbxbpgnd.fex" displayfield datafield accept="0" addalloption="0" IBIMR_folder="#adhocvdt5sp1" ibiapp_app>
</SELECT>


Look at the select object and you will notice that:

quote:

datatype="-1"


This is not normal. I changed it from 1 to -1. If you call UpdateData, then it will skip this object. When you ready to have it popluated you can do something like this:

var listelem = document.getElementById('listbox5');
listelem.setAttribute('datatype', 1);
populateChainElementFromServer(listelem);
//or UpdateData();
listelem.setAttribute('datatype', -1);


This forces that object to populate itself.

Fernando


Prod WF 8.1.04, QA WF 8.2.03, Dev WF 8.2.03
 
Posts: 277 | Registered: October 10, 2006Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Great solution. You are all terrific.
This problem just slipped by us, and in 7.6.4 we will have a clean option to set the default in a dynamic list.


Release 7.6.9
Windows
HTML
 
Posts: 226 | Registered: June 08, 2003Reply With QuoteReport This Post
Guru
posted Hide Post
Alan,

Thanks again. I can see your point about adding a break. In this particular case it's not too much of a problem as the list is quite short, but it I can see my self forgetting to use it when I had a long list.

Cheers

Stuart


WebFOCUS 8.2.03 (8.2.06 in testing)
 
Posts: 253 | Location: Melbourne, Australia | Registered: February 07, 2007Reply With QuoteReport This Post
Gold member
posted Hide Post
Thanks all, for the suggestions and examples.

We'll play with the javascript side just to sharpen our skills, but hold off until 7.6.4 so we can keep it on the server side (that's where the logic to determine current term against a DB2 calendar table resides, and I shudder at the thought of trying to execute a DB2 pull 'n' parse initiated from javascript Smiler

Best Regards!

-- Dan

University of Nebraska at Omaha
Prod: WF 7.6.2 MRE/BID/DataMigrator
Test: same
 
Posts: 63 | Registered: March 07, 2006Reply With QuoteReport This Post
Gold member
posted Hide Post
We've unpacked 7.6.4 into our TEST environment, and I've been working on the fixed solution for providing a SELECTED tag on a dynamic drop-down list. The solution appears to be a new "Selected Value" input box under the Parameters tab in HTML Layout Manager. It works as advertised, which is fine if we want to bind a static, hardcoded value to be always selected to a launch page if it appears in our dynamic list. But that defeats what we're trying to do -- we need to be able to dynamically populate a drop-down list *AND* dynamically choose the default, selected value.

I've checked the documentation in "Customizing Dynamic Parameters" within the online help on Dev Studio 7.6.4 and there is nothing indicating any enhancement which provides that capability on the XML output stream from our dynamic FEX.

Perhaps I've been spoiled for too many years with PHP, but we'd really like to avoid hacking the DOM via javascript to perform this simple task -- it really shouldn't be this messy. Am I missing something?

Regards,

-- Dan


WebFOCUS 8.8.05M (Prod)/8.0.09(Sandbox) Windows
 
Posts: 56 | Location: Omaha, Ne USA | Registered: October 15, 2007Reply With QuoteReport This Post
Guru
posted Hide Post
quote:
we'd really like to avoid hacking the DOM via javascript to perform this simple task -- it really shouldn't be this messy. Am I missing something?


I agree with Dan 100% - It is simple enough to provide an extra column of true/false in the FEX and HTML Layout Painter grabs it and interpret item[i].selected for the listed items.
I am in the minority group that haven't take the javascript 101 and afraid to take the solution given here and mess with the existing codes. So I hope IBI have addressed this issue or the users will be in their dreams to see the desirable default value from a drop down box.


Regards,

Hua


Developer Studio 7.6.11
AS400 - V5R4
HTML,PDF,XLS
 
Posts: 305 | Location: Winnipeg,MB | Registered: May 12, 2008Reply With QuoteReport This Post
Guru
posted Hide Post
Dan - Based on your original post, if you are using HTML Layout (Composer) it should be a simple matter of going to the Properties and Settings window for the parameter and filling in the 'Selected Value' box.

I do the same thing where I have drop-downs or listboxes populated by a procedure. When I fill in the Selected Value the list populates and the selected value is automatically selected regardless of where is is in the list.

Perhaps your issue is more complex?

Thanks,

Dan


7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
 
Posts: 394 | Location: St. Paul, MN | Registered: November 06, 2007Reply With QuoteReport This Post
Expert
posted Hide Post
Hopefully, Dan figured this out 2 years ago! Smiler


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1969 | Location: Centennial, CO | Registered: January 31, 2006Reply With QuoteReport This Post
Guru
posted Hide Post
To Dan Pinault & Tom Flynn,

I re-read the original post and hope I am not off the topic. Are you saying that there is a way to mark the default value from the populated list without using the jarvascript? Could you show me the direction how to accomplish this, if possible?

To be sure I not off topic, here is my requirement:

I have a fex to populate the last 24 months in descending order, and wants to select the past October as the default value. I need to keep the list in chronical order, and October will be on different position from month to month.


Thanks for the help,

Hua


Developer Studio 7.6.11
AS400 - V5R4
HTML,PDF,XLS
 
Posts: 305 | Location: Winnipeg,MB | Registered: May 12, 2008Reply With QuoteReport This Post
Expert
posted Hide Post
Hua,

OK. I am NOT a JavaScripter, so, I have to find other ways.
The following "may" give you an idea.
I call a fex to populate a combo/list box and re-sort the values to place the one I want at the top:

  
DEFINE FILE CENTORD
  YEAR1/I4YY  = ORDER_DATE;
  LST_YR/I4   = YEAR1 - 1;
  XYEAR1/A4   = EDIT('&YYMD.EVAL','9999');
  XYEAR2/I4   = EDIT(XYEAR1) - 1;
  XSORT1/A2   = EDIT('&YYMD.EVAL','$$$$99');
  XSORT2/I2L  = EDIT(XSORT1) + 1;
  SEL_YRMO/A6 = EDIT(LST_YR) | EDIT(XSORT2);
  DB_YRMO/A6  = EDIT(YEAR) | EDIT(MONTH);
  XSORT4/I2   = IF MONTH EQ XSORT2 THEN 1 ELSE 2;
  X_VALUE/A9  = DECODE MONTH (
                       01 'January'
		   02 'February'
		   03 'March'
		   04 'April'
		   05 'May'
		   06 'June'
		   07 'July'
		   08 'August'
		   09 'September'
		   10 'October'
		   11 'November' ELSE 'December');
 SHOW_VAL/A15 = EDIT(MONTH) | ' - ' | X_VALUE;;
END
TABLE FILE CENTORD
SUM
      SHOW_VAL
 BY XSORT4 NOPRINT 
 BY SHOW_VAL
ON TABLE PCHOLD FORMAT XML
END
-RUN


This puts month 10 at the top of the list AND is the selected value.
I have some extra code for current date, so, modify to fit your needs...

I'm sure there are better ideas out there, hopefully, they'll chime in...

hth

Tom

This message has been edited. Last edited by: Tom Flynn,


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1969 | Location: Centennial, CO | Registered: January 31, 2006Reply With QuoteReport This Post
Guru
posted Hide Post
Tom,

Thanks for your reply. I did the similar sort as yours, except when I give 24-month list, I have Oct08 and Oct07 on the top of the list and the rest in chronical order. Unfortunately the users immediately get confused what I am trying to do for them. If this is the only way, I will have to fine tuning the sort to push Oct07 down to where it belonged to. Again, like you said, there might be better ideas out there.

Thanks,

Hua


Developer Studio 7.6.11
AS400 - V5R4
HTML,PDF,XLS
 
Posts: 305 | Location: Winnipeg,MB | Registered: May 12, 2008Reply With QuoteReport This Post
Virtuoso
posted Hide Post
If I'm not mistaken, there IS now a "selected value" box that you can specify what you would like as the selected/highlighted value in your drop-down box. I would imagine if you put an amper variable there (for which you have used Dialogue manager to calculate to last october) you should get what you need. Since this will be part of the HTML page, it may have to be in the format !IBI.AMP.varname as opposed to &varname.

Doing it the "old" way using a fex to create and sort content of the control, try creating a month/year smart date field and sorting it that way instead of just by an alpha field ( create an alpha field with year first, then month and sort by that, while displaying MonthYr.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
 
Posts: 2298 | Location: Salt Lake City, Utah | Registered: February 02, 2007Reply With QuoteReport This Post
Guru
posted Hide Post
Darin,

Very interesting point.

I tried playing just the HTML Layout with the Selected Value Box, and ran it with hard-coded default value "1081001" or "October 08", it did not past to the drop-down list. When I checked the Add "ALL" option, entered the return value "1081001" in Selected Value Box, and replaced "ALL" with "October 08", it looked very nice when I click the run button, but the value past back the the fex is FOC_NONE.

Unless I miss something obvious, there is no point getting into the existing issue of setting default to a &variable in the dialogue manager.

Regards,


Hua


Developer Studio 7.6.11
AS400 - V5R4
HTML,PDF,XLS
 
Posts: 305 | Location: Winnipeg,MB | Registered: May 12, 2008Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Dynamic dropdowns - default selection?

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.