pp108 : addOption()

addOption()


It is used to add an option to the Select and List controls.

Syntax

Script oOption = ControlID.addOption(oOptionObject , bTransaction, iInsertBeforeIndex , bAllowDuplicates)


Return Value


Returns the option object that is added to the Select and List controls. The returned options contain the xml property, which contains its XML data node and business object.

Possible Values

oOptionObject The option object that must be added to the Select and List control.
bTransaction Boolean which denotes whether the object has to be updated for transaction. The default value is true, which updates the data associated with the control. This also fires the onchange event for enumerated Select and List controls.
iInsertBeforeIndex Integer that denotes the index before adding the Select or List options.
bAllowDuplicates Boolean that denotes whether duplicate items are allowed in the list box. The default value is true. If this property is set to false, then the option object is added only if it is unique.


Remarks


The following table lists the properties of an option object.

value A string that is not available to the user. It is used internally for transaction.
description String that is available to the user.



If the Select or List control exists in an XForm or in a grouping control in the XForm, you can use this method in the event handler which is executed when the Init Done event is fired.
If the Select or List control exists in a Table control, you can use this method in the event handler which is executed when the onBeforeBind event is fired. In this case, set the bAllowDuplicates parameter to False to avoid duplication of options.
Note: The value that you add to the Select or List control is not selected, by default.

Examples


This sample code demonstrates how theaddOption()method can be used to add an option to a Select control, after the XForm is loaded.

// Init Done event of the form.
function Form_InitDone(eventObject)
{
    // create the option to add.
    var option = {value:"0", description:"-- Select Employee --"};
    // add the option to the "employeeid" select control as the first option.
    employeeid.addOption(option,false,0,false);    
}


The value that you add to the Select or List control is not selected, by default.

The following code demonstrates how the method can be used to add an option to a Select control in a table, after the XForm is loaded.

// Adding an option to a select control in table.
// Before bind event of "employeeid" select control.
function employeeid_BeforeBind(eventObject)
{
    // create the option to add.
    var option = {value:"0", description:"-- Select Employee --"};
    // add the option to the "employeeid" field of the active row. 
    employeeid[EmployeesTable.getIndex()].addOption(option,false,0,false);
}

Applies to


Select, List

Related reference

removeOption()
removeOptions()
addOptions()
getSelectedOptions()
getAllOptions()