Class

BaseField

BaseField(props)

The BaseField class provides a generic structure and some default functionality for all components.

Extend this class to create custom widgets by overriding the default lifecycle methods.

Lifecycle methods:

  • setElement: Aaves the HTML element indicated by the id parameter as the main element of the widget.
  • buildDOM: Builds the initial HTML representation of the widget.
  • addListeners: Adds any listeners to listen for user interaction and react to it, for example by changing the inner state of the component.
  • setDefault: Updates the widget state and visual representation with the default value specified in the constructor.
  • setValue: Updates the widget state programmatically with an arbitrary value.
  • setDOM: Updates the visual representation of the component, usually executed after state changes to reflect them.

Saving and restoring state in the data tree:

The widget state can be saved or restored from the data tree by using the save() and restore() methods. Override them to provide custom saving and restoring functionality. Call save() and restore() from outside the widget to save its state on the data tree or restore it.

Changing the component state:

The component state can be changed by three methods:

  • By setting the value programmatically calling setValue().
  • By interacting with it.
  • By changing the associated datanode and calling widget.restore().

Reacting to changes in the component state from outside of it:

Either subscribe to changes on the datanode or pass an apply function to the constructor:

datanode.subscribe('lt-my-widget-data', data => { });

let myWidget = new MyWidget({
  id: 'lt-my-widget',
  key: 'lt-my-widget-data',
  apply : function(value) {  }
}
Constructor

# new BaseField(props)

Parameters:
Name Type Attributes Default Description
props Object

Object of properties

id String

Id of the field

default * <optional>
null

Default value

preview Boolean <optional>
true

If the value can be previewed

onSave function <optional>
null

Callback for the save action. With one param as the new value.

canSave Boolean <optional>
true

If the field can save ??? TODO: Better description

View Source fields/BaseField.js, line 56

Methods

# addListeners()

Listener for on change properties By default is change event for a Input[type=text] field

View Source fields/BaseField.js, line 128

# buildDOM()

Builds the DOM representation of the widget By default is empty for a Input[type=text] field

View Source fields/BaseField.js, line 172

# getCleanId() → {String}

Get the clean id name (without # or .)

View Source fields/BaseField.js, line 161

Clean id

String

# getValue() → {*}

Get the current value of the field

View Source fields/BaseField.js, line 153

Value of the field

*

# restore()

Restore the previous value & trigger onChange callback

View Source fields/BaseField.js, line 196

# save()

Save action trigger onSave method

View Source fields/BaseField.js, line 188

# setDefault()

Set default value (Normally only in the constructor)

View Source fields/BaseField.js, line 110

# setDOM()

Set the value to the DOM element By default apply like a Input[type=text]

View Source fields/BaseField.js, line 178

# setElement()

Set the element to listen on changes Overload in some cases

View Source fields/BaseField.js, line 120

# setValue(value)

Programmatically set the value of the widget and update the DOM to reflect the changes.

Parameters:
Name Type Description
value *

View Source fields/BaseField.js, line 143