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:

  • Configuration driven by specifying functions within Alpaca options
  • Using the postRender method and calling on() for individual fields
  • By extending Alpaca Field implementation classes

This document covers how to set these up.

Event Types

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
  • event
The mouse moved over the dom element for a field
mouseout Field
  • event
The mouse moved out of the dom element for a field
change ControlField
  • event
The value of the field changed
focus ControlField
  • event
The control field has received focus
blur ControlField
  • event
The control field has lost focus
keypress ControlField
  • event
A key was pressed in the control field
keydown ControlField
  • event
A key was pressed down in the control field
keyup ControlField
  • event
A key was released in the control field
click ControlField
  • event
The left mouse button was clicked in the control field
move ContainerField
  • event
A child item was moved.
add ContainerField
  • event
A child item was added.
remove ContainerField
  • event
A child item was removed.
ready Field
  • event
The DOM element backing the field was injected into the display.

Configuration Driven

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.

Using the postRender callback

For any field, you can register an event handler by calling on for the field instance.

In this example, we register two event handlers.

  • The first one listens for the change event on the title field.
  • The second one listens for the 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.

Extending Field implementation classes

You can extend the base field classes that Alpaca offers and register event handlers directly.

© 2019 Gitana Software, Inc.

Alpaca is sponsored by