Option list

The option list, also know as a drop down menu, is a simple control for selecting one or multiple elements from a collection of items.

/OptionList.png

Using the option list only requires a few lines of code, as shown below.

public function Render()
{
    $list = new SMOptionList("UniqueId");

    $list->AddOption(new SMOptionListItem("UniqueId1", "Text field", "field"));
    $list->AddOption(new SMOptionListItem("UniqueId2", "Textbox", "box"));
    $list->AddOption(new SMOptionListItem("UniqueId3", "Checkbox", "check"));

    if ($list->PerformedPostBack() === false)
        return $list->Render();
    else
        return $list->Render() . "<br>Option selected: " . $list->GetSelectedValue();
}
The example above creates the list shown in the example image in the top of this page. When a user selects an item, a post back is automatically performed, and the text "Option selected: XYZ" is written underneath the option list.


Using multi select

The option list also supports multiple selections. Simply set the Multiple attribute after creating an instance of the option list, as shown below.

$list = new SMOptionList("UniqueId");
$list->SetAttribute("SMOptionListAttribute::$Multiple, "multiple")
Notice that the GetSelectedValue() function can be used to get both single and multi selections. Multiple items are simply separated by semi colon (;).


SMOptionList class

Function Return type Description
__construct($id:string)
Create instance of option list. Use a unique ID by prefixing the value with the name of the extension.
GetId() String Get ID of instance assigned using constructor.
GetClientId() String Get ID used client side. This is useful for interacting with the control using JavaScript.
AddOption($option:SMOptionListItem)
Add option/item to the option list. See description for SMOptionListItem class for further information.
RemoveOption($id:string)
Remove option with the specified unique ID.
SetOptions($options:SMOptionListItem[])

Replace the internal collection of options.
GetOptions() SMOptionListItem[] Get the internal collection of options.
GetOption($id:string) SMOptionListItem Get option list item by unique ID.
SetAutoPostBack($value:boolean)
Set True to have control perform a post back when user changes the value of the control. Set False to disable auto post back (default).
GetAutoPostBack() Boolean Get value indicating whether auto post back is enabled or not.
SetAttribute($attr:SMOptionListAttribute, $value:string)
Set specified attribute using the SMOptionListAttribute enum.
GetAttribute($attr:SMOptionListAttribute) String Get specified attribute value.
SetSelectedValue($value:string)
Specify value (not display value) automatically selected.
GetSelectedValue()
String
Get value selected after post back. If multiple selections have been made, each item is separated by semi colon (;).
PerformedPostBack()
Boolean
Returns True if the control caused a post back (possible when auto post back is enabled), otherwise False.
SetRender($value:boolean)

Set True (default) to have control rendered, False not to.
GetRender() Boolean Get value indicating whether control will be rendered or not.
Render() String Get code representing the control.


SMOptionListItem class

Function Return type Description
__construct($id:string, $title:string, $value:string)   Create instance of item for the option list. The ID must be unique.
GetId() String Get ID specified in constructor.
GetClientId() String Get ID used client side. This is useful for interacting with the element using JavaScript.
SetTitle($value:string)   Change title to the specified value.
GetTitle() String Get title (display value).
SetValue($value:string)   Change internal value to the specified value.
GetValue() String Get internal value.
Render() String Get code representing an option list item.


SMOptionListAttribute enum

Enum value Description
Value Represents the attribute of the same name
Disabled
Represents the attribute of the same name
Title
Represents the attribute of the same name
Style
Represents the attribute of the same name
Class
Represents the attribute of the same name
AccessKey
Represents the attribute of the same name
TabIndex
Represents the attribute of the same name
Multiple
Represents the attribute of the same name
OnFocus
Represents the attribute of the same name
OnBlur Represents the attribute of the same name
OnChange Represents the attribute of the same name
OnClick Represents the attribute of the same name
OnDblClick Represents the attribute of the same name
OnMouseDown Represents the attribute of the same name
OnMouseUp Represents the attribute of the same name
OnMouseOver Represents the attribute of the same name
OnMouseMove Represents the attribute of the same name
OnMouseOut
Represents the attribute of the same name
OnKeyPress Represents the attribute of the same name
OnKeyDown Represents the attribute of the same name
OnKeyUp Represents the attribute of the same name