It seems for me that there is a simpler solution using a simple array iteration (should be faster, too).

function setComboBoxValue(combo, leftValue) {
  for (var i=0, a=combo.getList().getChildren(), l=a.length; i<l; i++) {
    if (a[i].getValue() == leftValue) {
      return a[i];
    }
  }
}

Hope this helps.

Sebastian


 
CRACKED IT! I'm sure someone will reply with a two line fix later, but I'm so damned happy I don't care.
 
If anyone has the same problem, here is the generic function I used for setting the default value of the ComboBox to the left value of the dropdown (Like HTML) rather than the native index of the list items.
 
// Special function for ComboBox so we can set the default value of the dropdown
// by passing the comboBox object, and the default value
function setComboDefault(combo, leftValue) {    
     ListItems = combo.getList().getChildren();
     for( var key in ListItems ) {
          if(ListItems[key].getValue() == leftValue) {
               combo.setSelected(ListItems[key]);
          }
     }
}
 
Remember this will only work if your ComboBox objects are created using the same Database table ID's that you are passing to this function.
 
Aaron
----- Original Message -----
Sent: Tuesday, December 12, 2006 6:50 PM
Subject: Re: [qooxdoo-devel] Setting Combobox Default ListItem

I am still having major trouble with this if anyone can please help.
 
Here is exactly what I am doing:
 
I have made my own class of ComboBox that gets values from a database in pairs of [id]=>[text value];
 
The [text value] is the visible part in the dropdown, while the [id] is the value of the selected item. This id is stored in the database when the record is saved.
 
This part works fine.
 
The problem is when I display a record for editing, I want to setSelected the relevant item in the dropdown, using the id again supplied from the database.
 
I have this function which I pass the ComboBox object, and the id value of the list item I am trying to select:
 
function setComboDefault(combo, leftValue) {
 listItem = (combo.getList().getChildren()[leftValue]);
 combo.setSelected(listItem);
}
 
This function only works by the native index of the ComboBox (e.g. 0 to N).
 
Obviously, ComboBoxEx would solve my problem rather easily, however there is a bug in this object where it cannot be used on a Window.
 
So what I need to do can be seen in this algorthym:
 
function setComboDefault(Object ComboBox, String IdValue) {
   
    ListItems = get all list items of ComboBox
 
    for(each ListItems as ListItem) {
        if (ListItem value == IdValue) {
            ComboBox.setSelected(ListItem);
        }
    }
}
 
Can anyone help with this please?
 
Aaron
----- Original Message -----
Sent: Wednesday, November 22, 2006 5:59 PM
Subject: Re: [qooxdoo-devel] Setting Combobox Default ListItem

Thanks mate, that does work, but I had to be able to set it using the initalVal parameter I passed to the function, with out using a loop.
 
easily done with if-else with two items but some of them have many items, and are dynamic.
 
This is what I came up with and it works:
 
field.setSelected(field.getList().getChildren()[initialVal]);
 
Cheers
Aaron
----- Original Message -----
Sent: Wednesday, November 22, 2006 3:46 PM
Subject: Re: [qooxdoo-devel] Setting Combobox Default ListItem

field.setSelected(item_no);

Just a guess....

-Jonathan.

On 11/22/06, Aaron Cooper <[EMAIL PROTECTED] > wrote:
Hi Guys,
 
Spent a good 3 hours trying to do this simple task, and can't find the way of doing it in the API or Demos.
 
Take this simple Yes/No Combobox class that I have made:
 
function ftmDataEntryYesNo (name, xPos, initialVal) {
 var field = new qx.ui.form.ComboBox();
 field.setCssClassName("ftm-text-fields");
 field.setTop(xPos);
 field.setWidth(75);
 field.tagName = name;
 
 var item_no = new qx.ui.form.ListItem("No");
 item_no.setValue(0);
 
 var item_yes = new qx.ui.form.ListItem("Yes");
 item_yes.setValue(1);
 
 field.add(item_no, item_yes);
 
 //Set the initial value

 field.setSelected(field.getList().item_no);
 
 return field;
}
What is wrong there? I know about field.getList().getLastChild(), the above code came from a demo example using it. But how do I select a specific child?
 
Cheers
Aaron

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel




-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to