Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Mar 23, 2008 16:48
open dhtmlx forum
combo setting value/text when using auto/complete with xml from database

We are using a combo which loads a dynamically generated xml file (values are loaded from a database).

We want to set the value of a field before anything is typed into the field.

I assumed that when we use setComboValue() function it would automatically query the XML to get the corresponding text value to be shown in the field, but it doesn't it just shows the value passed to setComboValue().

How can we pass the combo an ID of an option and have it load it appropriately?

Answer posted by Support on Mar 24, 2008 02:50
The combo can't just load a single option from DB, you can force loading reaction similar to one when user typed value by next code

combo.setComboText("some")
combo.filterSelf(); // will cause DB call and loading list of options with "some" text
Answer posted on Apr 19, 2009 13:10
So can we use setComboValue and setComboText together to pre-populate the field?  For instance if we are using the fields on a "Edit" form where some data needs to be loaded from a database that was already entered.
Answer posted by Alex on Apr 20, 2009 05:21
You can use either setComboValue or setComboText. There is no need to use them together.
Answer posted on Apr 20, 2009 12:30
But we want the displayed text to be different than the actual value submitted when the form is submitted.

Take for instance this example where we have a username and user ID.

We want the value = the user ID like a number say 55.

But the text shown to be the username.


Answer posted by Alex (support) on Apr 21, 2009 03:11

In this case you should select option by option index. And then set combo text:

combo.selectOption(index);

combo.setComboText(some_text);

Answer posted on Apr 21, 2009 07:47
Ok but how are we going to know the index?


Answer posted by Alex on Apr 22, 2009 04:53
There is getIndexByValue method. Please, see the full list of combo API in the documentation dhtmlxCombo/doc/alpha.html