Callbacks
Alpaca provides several places where you can hook in callbacks.
- Events - events are raised when the user interacts with fields. You can register callbacks
to handle these events, adjust field state or other operations. - Observables - each field maintains an observable that you can subscribe to.
Subscribing to an observable means that you're listening for changes to its value. You can also use observables to
interrogate and find values of fields within namespaces. This lets you find values of other fields on the same form
or within other forms on the same page (using scopes). - Validation - each field has its own validation logic which is coded into the field
and runs by default, respecting the underlying JSON schema mechanics. You can also register custom validation logic
within your JSON config on a per-field basis. - Forms - let you define buttons and submit handlers.
- Wizards - let you define Next, Previous and Submit handlers including custom validation
between transitions.
In general, the Alpaca model is an asynchronous one. The framework assumes that external, third-party systems may need
to be consulted for things like validation, and so in general callbacks are utilized to indicate completion of the
handling. Exceptions to this are event handlers (which are modeled off of DOM event handlers, also synchronous) and
the primary postRender callback.
The postRender callback
The postRender
callback is the most common callback that you will use. This is a top-level callback that
gets fired once the form has completely rendered. It carries a single argument which is the top level control instance.
You can use this control instance to get all all of the child fields.
Here is an example of its use. This simply logs the initial values to console.
{% endraw %}