The Combobox component has a robust and flexible Javascript API that allows developers to modify the behaviour of the component at runtime.
Accessing the Combo object
You can use the nitobi.getComponent to get a reference to the ComboBox object.
var myCombo = nitobi.getComponent('comboId');
The ComboBox object has a number of methods you can use to affect the component's behaviour, but you may also want to access the objects for the ComboList and the ComboTextBox:
var myComboList = myCombo.GetList(); var myComboTextBox = myCombo.GetTextBox();
For a full list of API methods, please see http://api.nitobi.com - below are some code snippets to help get you started with the API.
Disable/Enable the ComboBox
The SetEnabled method of the Combo object can help you with this - very simply:
myCombo.SetEnabled(false); // disable ComboBox myCombo.SetEnabled(true); // enable ComboBox
Getting the Current Value
Because the ComboBox can handle datasets with multiple fields, getting the current value for the ComboBox may mean getting the text value of the Combo input box, or getting the values for all the fields of the selected row. Getting the text value is very simple:
var textValue = myCombo.GetTextValue()
There is also a Combo method called GetSelectedRowValues that does just that - it returns an array of all the field values for the selected row:
var selectedValues = myCombo.GetSelectedRowValues(); // get all fields from the selected row var selectedFifthField = myCombo.GetSelectedRowValues()[4]; // get fifth field (zero-indexed) of the selected row
Focusing the Combo
If you want to programmatically set focus to your ComboBox, it's very easy:
myCombo.SetFocus()
Showing and Hiding the List
If you have a reference to the list at hand, this is very easy - even if you don't, it's not too bad:
myComboList.Show(); myCombo.GetList().Show(); // these two lines produce the same result myComboList.Hide(); myCombo.GetList().Hide(); // these two lines produce the same result
Select a Row by Row Index
This one is a little more tricky, so we can write a function to do this:
function selectRowInMyCombo(row) { myComboList.SetSelectedRow(row); myComboTextBox.SetValue(myCombo.GetSelectedRowValues()[myComboTextBox.GetDataFieldIndex()]); }
Here we set the correct value in the XML data source (through the List object), and then set the TextBox's value based on which selected field populates the TextBox.
If you have any more questions about using the Combo API, please let us know.