Focal Point
Preselect Combobox value on Maintain - I'm still confused...

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

February 19, 2007, 01:27 PM
Anatess
Preselect Combobox value on Maintain - I'm still confused...
I have read several documentation on the combobox in Maintain as well as some Focal Point discussion on the topic but I am still confused.

This is what I'm trying to do. I have a single-select combobox on a form that is bound to a field in a stack. The options for this combobox is added by using the "As Entered Here" radio button on the list property. I manually entered the Text and its corresponding value in the property.

Adding a new record works fine (just like the other focal point post on this same subject). Now, I want to update (okay, don't roll your eyes just yet). The stack is now filled with the current value on the database. And so, the doc says not to bind this thing to a pre-filled stack because it will just overwrite what is in there. So, I bound this combobox to a scratch variable instead and created a hidden textbox that is bound to the stack field. after the "update button" is clicked, then it copies the value of the variable to the stack. It makes sense theoritically.

So, my first problem is setting the selectedIndex to the proper value before the form is shown. The example on the doc says to put the options in a stack, cycle through it on winform show_inactive, yada yada. Well, in my case, the options are not in a stack - they're manually entered in the "As Entered Here" thingee. So, what I did instead is to put a javascript on the form onload event and did something like this (okay, this is off the top of my head, so syntax errors may occur, but the point is the logic, not the syntax):

for(i=0;i "less than" document.form1.mycombobox.length;i++){
if (document.form1.mycombobox.options(i).value == document.form1.stackfield.value){
document.form1.mycombobox.selectedIndex = i;}
}

** the less than symbol doesn't show up right in the post, but y'all probably already know that.

Well, this didn't work - because, for some crazy reason, if I do a view source on the form when it runs, the actual VALUE of the options are changed to selectedIndex+1! So, it will never be the same as the value of the stackfield.

If I look at the .mnt file using notepad, the value for the options is what it should be, so I guess webfocus changes it at run-time/compile time somehow.

So, I guess this is not the way to do it... what's an easy way to do this?

I'm on 7.1.4 running on windows.


WF 8.1.05 Windows
February 19, 2007, 03:21 PM
Alan B
Firstly, I don't quite do this the way you describe. The way I approach this is to set up a stack of the variables that I want in the combo box.
   
.
.
Declare comboOptionStack/Stack of a0;
Declare comboOptionStackIndex/i6;
.
.
comboOptionStack(1)='myOption1';
comboOptionStack(2)='myOption2';
comboOptionStack(3)='myOption3';
.
.

Then I insert list items into the combo box from this Stack. I bind the combo box value to comboOptionStackIndex;

In the add or update record I will use:
recordStack.fieldNameForOption(1)=comboOptionStack(comboOptionStackIndex)
.
.


When I get a record for update into recordStack, then I use the same technique that I used for MikeM a few posting ago to display the right value.
Case GetStackIndex
Declare cntr/i6;
comboOptionStack.FocIndex=-1;
repeat comboOptionStack.FocCount cntr=1;
if (recordStack.fieldNameForOption(1) eq comboOptionStack(cntr) then comboOptionStack.FocIndex = cntr;
if comboOptionStack.FocIndex gt -1 goto exitrepeat;
endrepeat cntr=cntr+1;
EndCase



Hope this helps.

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007
February 20, 2007, 10:04 AM
Anatess
Hi Alan,

I'm still digesting this. It is a wee bit much for one combobox, no? But then if it is worth doing, it is worth doing right...
Just one question. If you have a combobox value different from the text, do you then put the text as a another field in the comboOptionsStack?


WF 8.1.05 Windows
February 20, 2007, 12:29 PM
Alan B
You're right, it is a bit much for a combobox, but they are a bit more complicated than a plain edit box. You get used to it.

And yes, after the endrepeat put in something like:
if comboOptionStack.FocIndex eq -1 begin
comboOptionStack(comboOptionStack.FocCount+1)=recordStack.fieldNameForOption(1);
comboOptionStack.FocIndex = comboOptionStack.FocCount;
endbegin

Don't forget to reset the stack afterwards though.
good luck.

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007