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?
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
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.
You can use either setComboValue or setComboText. There is no need to use them together.
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.
In this case you should select option by option index. And then set combo text:
combo.selectOption(index);
combo.setComboText(some_text);
Ok but how are we going to know the index?
There is getIndexByValue method. Please, see the full list of combo API in the documentation dhtmlxCombo/doc/alpha.html