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:
postRendermethod and calling
on()for individual fields
This 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).
||The mouse moved over the dom element for a field|
||The mouse moved out of the dom element for a field|
||The value of the field changed|
||The control field has received focus|
||The control field has lost focus|
||A key was pressed in the control field|
||A key was pressed down in the control field|
||A key was released in the control field|
||The left mouse button was clicked in the control field|
||A child item was moved.|
||A child item was added.|
||A child item was removed.|
||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.
For any field, you can register an event handler by calling
on for the field instance.
In this example, we register two event handlers.
changeevent on the
changeevent 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.