Custom Fields

Alpaca has a pretty inclusive field library that you can use straight away. Fields are simply referenced by their type within your Alpaca forms configuration. If you don't provide specific field types to use, Alpaca guesses at sensible defaults for you.

You can also create your own fields. Alpaca fields are object-oriented (essentially) so that you can extend existing fields, override methods and modify behaviors. The result is less work and a complete extensibility layer so that you can use Alpaca in your projects while building your own fields and UI components.

For a complete example of how to build fields, the best path is to look at the Alpaca source code. After all, Alpaca is completely open-source and so the source code is always going to be the very best place to go.

Here we provide some lightweight guidance here on how to build your own fields.

Example: Capitalize all Words

Let's take a look at a quick and dirty example. Here we create a new field with the type custom1 that extends the text field. When the user enters a value and it is set onto the field, we override the setValue method and capitalize all of the words. We then proceed to the base method to let things proceed on their merry way.

{% raw %} {% endraw %}

Example: Capitalize all Words (with Format)

We can use the same approach as the previous example while extending the JSON schema format settings. Let's add our own format called "custom2".

{% raw %} {% endraw %}

Example: Making HTTP Calls

Here is an example where a custom field might use the setupField method to do some custom, long-duration work that could cause the rendering order of the nested objects to get out of order since loading of sub-fields in done in parallel.

This ensures that the order is preserved.

{% raw %} {% endraw %}