Alpaca allows you to bind event handlers to containers and individual fields that are triggered either directly or via propagation.
Event handlers can be registered in the following ways:
postRender
method and calling on()
for individual fieldsField
implementation classesThis document covers how to set these up.
In general, event handlers are invoked with the this
reference set to the field instance being handled.
This lets you use this.getValue()
to get the current value of the field and also gives you a way to
access observables and traverse through to other fields in the hierarchy. The
event object itself is also passed as an argument to event handlers so that you can control the lifecycle of the
event before it makes its way through the DOM.
All event handlers are synchronous in nature (similar to actual DOM event handlers).
Event | Context | Arguments | Description |
---|---|---|---|
mouseover | Field |
|
The mouse moved over the dom element for a field |
mouseout | Field |
|
The mouse moved out of the dom element for a field |
change | ControlField |
|
The value of the field changed |
focus | ControlField |
|
The control field has received focus |
blur | ControlField |
|
The control field has lost focus |
keypress | ControlField |
|
A key was pressed in the control field |
keydown | ControlField |
|
A key was pressed down in the control field |
keyup | ControlField |
|
A key was released in the control field |
click | ControlField |
|
The left mouse button was clicked in the control field |
move | ContainerField |
|
A child item was moved. |
add | ContainerField |
|
A child item was added. |
remove | ContainerField |
|
A child item was removed. |
ready | Field |
|
The DOM element backing the field was injected into the display. |
For any field, you can specify an events
sub-object that declares handlers by event name.
Here is an example where we register a whole set of event handlers for different kinds of events. These all dump out to console. Open up your dev tools to look at the console output.
postRender
callbackFor any field, you can register an event handler by calling on
for the field instance.
In this example, we register two event handlers.
change
event on the title
field.change
event on the top level container field.Both get notified. When the child field changes its value, it changes the top field's value as well.
You can extend the base field classes that Alpaca offers and register event handlers directly.