Fieldset (sub form)

Fieldsets are used to group input fields and controls logically and functionally. Usually the fieldset is set to create a visual box around elements belonging together, as shown in the image below.


/GUIComponents.png


Since all input controls are part of the same HTML form element, the fieldset is also used to create sub forms, allowing the programmer to define which control (usually a button) is triggered, when ENTER is pressed in the given sub form. The example below demonstrates this.

function Render()
{
    $txtName = new SMInput("MyExtensionName", SMInputType::$Text);
    $txtAge = new SMInput("MyExtensionAge", SMInputType::$Text);

    $cmdSave = new SMLinkButton("MyExtensionSave");
    $cmdSave->SetTitle("Save data");

    $fieldset = new SMFieldset("MyExtensionFieldset");
    $fieldset->SetContent($txtName->Render() . "<br>" . $txtAge->Render() . "<br><br>" . $cmdSave->Render());
    $fieldset->SetLegend("Name and age");
    $fieldset->SetPostBackControl($cmdSave->GetClientId());
}
In the example above, two input fields are created, and rendered inside a fieldset. Notice the last line of code, where we tell which control is set as the post back control, if ENTER is pressed. The condition below will be true if the Save button is clicked, as well as if ENTER is pressed in one of the input fields.

if ($this->cmdSave->PerformedPostBack() === true)
{
    // Save data
}
SMFieldset class

Function Return type Description
__construct($id:string)   Create instance of fieldset with unique ID.
GetId() String Get ID set in constructor.
GetClientId() String Get ID used client side. This is useful for interacting with the control using JavaScript.
GetLegend String Get text used in legend (title).
SetLegend($value:string)   Set text used in legend (title).
GetContent() String Get content from fieldset.
SetContent($value:string)   Set content displayed in fieldset.
SetAttribute($attr:SMFieldsetAttribute, $value:string)   Set attribute. Use enum SMFieldsetAttribute to specify which attribute to define.
GetAttribute($attr:SMFieldsetAttribute) String Get attribute value. Use enum SMFieldsetAttribute to specify which attribute value to retrieve.
SetPostBackControl($controlId:string)   Set ID of control to set as post back control, when ENTER is pressed in the fieldset (sub form). Use $control->GetClientId() to get the control ID.
GetPostBackControl() String Get the ID of the post back control assigned using SetPostBackControl($controlId:string).
SetDisplayFrame($value:boolean)   Set True to display frame around sub form (default) or False to disable it.
GetDisplayFrame() Boolean Get value indicating whether a border/frame will be rendered around the fieldset.
SetRender($value:boolean)   Set True to render fieldset with its content, False not to.
GetRender() Boolean Get value indicating whether fieldset will be rendered when Render() function is called.
Render() String Get HTML defining fieldset with all its controls.


SMFieldsetAttribute enum

Enum value Description
::$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
::$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