widget
The widget class provides an interface to manage properties and actions of active widget.
This class is a transition class between the static class and more specific classes like input, button, listbox…
Normally, you'll never have to instantiate the **cs**.widget class, since instantiation is automatic with a more specialized widget.
Hierarchy
ℹ️ Important
- This class inherit from the
staticclass - To simplify the distinction between form objects and object type, this documentation uses the term
widgetfor all form objects, whether static (a line, a rectangle…) or not (a button, a subform…). - All functions that return
Thisreturn the current widget object and can include one call after another.
Properties & Functions
Inherited properties and functions are described in the parent classes:
Specific property sections:
Value
| Properties | Description | Type | Writable |
|---|---|---|---|
| .isEmpty | Returns True if the widget value is empty * | Boolean |
x |
| .isNotEmpty | Returns True if the widget value is not empty * | Boolean |
x |
| .value | The value associated to the widget ** | Variant |
✓ |
* Empty values are : Null, 0, !00-00-00 !, ?00:00:00 ?, { }, [ ], False, an empty string or an empty image.
| Functions | |
|---|---|
.clear () →This |
Sets empty value* to the datasource according to its type |
.getValue ( ) →This |
Returns the value associated to the widget ** |
.setValue (value ) →This |
Sets the value of the widget |
** For a text input box that has the focus, returns text as it is being entered.
Data Source
| Properties | Description | Type | default | Writable |
|---|---|---|---|---|
| .datasource | Sets the data source for the widget | 4D.Formula | Text Formula |
✓ |
| Functions | |
|---|---|
.setDatasource (datasource :4D.Function) →This |
Sets the data source for the widget |
Entry
| Properties | Description | Type | Writable |
|---|---|---|---|
| .contextMenu | Context menu associated with the widget or not | Boolean |
✓ |
| .enterable | Makes the widget enterable or not | Boolean |
✓ |
| .helpTip | Associated help message | Text |
✓ |
| Functions | |
|---|---|
.getHelpTip () →Text |
Returns the associated help tip |
.getShortcut () →Object |
Returns the associated shortcut definition {key (Text), modifier (Integer)} |
.notEnterable () →This |
Makes the widget non-enterable |
.removeHelpTip () →This |
Removes the associated helptip |
.setEnterable ({enterable }) →This |
Makes the widget enterable according to enterable parameter Default is True |
.setHelpTip (tip ) →This |
Sets the associated help tip. If tip is ommitted, the help tip will be removed. |
.setShortcut (key {; modifier }) →This |
Sets the associated shortcut |
Events
| Properties | Description | Type | Writable |
|---|---|---|---|
| .events | The widget’s form events (codes) | Collection |
✓ |
| Functions | |
|---|---|
.addEvent (code ) →This.addEvent (codeCollection ) → This |
Appends one or more event codes to the widget |
.catch ({event }) →Boolean.catch (event ; code ) → Boolean.catch (event ; codeCollection ) → Boolean |
Returns True if the widget is causing the form event & executes the callback formula if it exists. Pass an event code or collection of event codes to restrict the response to these events. |
.removeEvent (code ) →This.removeEvent (codeCollection ) → This |
Removes one or more event codes to the widget |
.setEvents (code ) →This.setEvents (codeCollection ) → This |
Sets one or more event codes to the widget |
Callback
| Functions | |
|---|---|
.setCallback ( formula | This.<function>}) →This |
Associates a callback to be executed when a form event occurs |
| .execute () | Executes the callback associated with the widget if it exists |
User Data
📌 User data can be anything you want to attach to the widget and retrieve later..
| Properties | Description | Type | Writable |
|---|---|---|---|
| .data | Any user data you want attach to the widget | Variant |
✓ |
| Functions | |
|---|---|
.setData (object ) →This |
Set or enrich the data property with the contents of an objectIf the data property is not Null or is not an Object, an error is raised. |
Drag & drop
| Properties | Description | Type | Writable |
|---|---|---|---|
| .uri | The Uniform Resource Identifier (URI) associated with the widget | Text |
✓ |
Actions
| Properties | Description | Type | Writable |
|---|---|---|---|
| .action | Name and (if any) parameter of the Standard action associated with the widget | Text |
✓ |
| .draggable | The dragging option | Boolean |
✓ |
| .droppable | The drop-off option | Boolean |
✓ |
| Functions | |
|---|---|
.setDraggable (enable {; automatic }) →This |
Sets the drag options |
.setDroppable (enable {; automatic }) →This |
Sets the drop options Default: accept drop and not automatic |
.setNotDraggable () →This |
Disables drag option |
.setNotDroppable () →This |
Disables the droppable option |
Miscellaneous
| Properties | Description | Type | Writable |
|---|---|---|---|
| .pointer | Returns the pointer to the widget ⚠️ Nil pointer if data source is an expression |
Pointer |
x |
| .newUI | True when modern OS theme is active (FluentUI on Windows, LiquidGlass on macOS) |
Boolean |
x |
| Functions | |
|---|---|
.focus () →This |
Gives focus to the widget |
.isFocused () →Boolean |
Returns True if the widget is focused |
| .postClick () | Simulates a mouse click on the widget |
.touch () →This |
Forces the update of the widget by reassigning the same value to the data source |