create
[ Function ] [ Deprecated ]
public static create(
element: JQuery,
unused?: null,
parent?: TcHmi.Controls.System.baseTcHmiControl | null
): TcHmi.Controls.System.baseTcHmiControl | undefined;Function for programmatically creating control instances based on a JQuery element object.
![]() | Since version 1.10 this function is considered obsolete. Instead, the function createEx should be used. |
Parameters
Name | Type | Description |
|---|---|---|
element | New control as a JQuery object. | |
unused [ optional ] | Must be set if parent is to be used. | |
parent [ optional ] | Parent control of the new control. This is used to check access rights if they depend on the parental control, for example.
This parameter should not be set if a control is created dynamically at application level ( CodeBehind ) and then passed to a ContainerControl (View, Content, Container etc.). The parent/child relationship is created dynamically when the control is added to the corresponding ContainerControl using the addChild function.
If a control is created dynamically within another control, this other control is the logical parent control and must be passed when the new control is created, so that properties such as access rights can be applied to the child control, and the system has the option to destroy the child control if the parent control is destroyed. |
Return value
Type | Description |
|---|---|
The control object or |
![]() | Available from 1.8 |
Example – TypeScript
In this example, a button is dynamically created within a separate control and added to the DOM.
// Place in __prevInit of your own control:
var myButton = TcHmi.ControlFactory.create<TcHmi.Controls.Beckhoff.TcHmiButton>
(
$('<div id="newbutton" data-tchmi-type="TcHmi.Controls.Beckhoff.TcHmiButton"></div>'),
null,
this // <- this sets the framework parent/child relationship,
// but does not add it in the DOM
);
if (!myButton) {
// handle error
throw new Error(this.getId() + ': Could not create sub button');
}
// Add the button to the DOM at a specific position
this.getElement().append(myButton.getElement());