Validation Examples

Example 1:

Required field.

Example 2:

Field with disallowed values.

Example 3:

Field with default value.

Example 4:

Field with schema enum properties.

Example 5:

JSON Schema validation (valid).

Example 6:

JSON Schema validation (invalid).

Example 7:

Custom validator.

Example 8:

Custom validator.

Example 9:

No validation of readonly fields.

Is this form valid?

Example 10:

DEBUG loggings of ignored fields outside schema

Example 11:

Invalid field with view '''bootstrap-create''' (no init validation)

Example 12:

Custom validator (with view '''bootstrap-create''').

Example 13:

Array field with required sub-properties.

Example 14: Non-required field with allowOptionalEmpty

The allowOptionalEmpty option allows you to identify optional fields that you wish to have validate successfully successfully when they have empty values.

Shown here is an email field. Email fields run a regex to validate the the email address provided is structurally correct. However, if the field is optional (meaning that the schema required is false), then the user may elect not to fill in this field.

When running validation on the form, technically speaking, an empty value for the email field would be considered invalid (since the data does not conform to the expected structure). The allowOptionalEmpty option tells Alpaca to bypass this validation logic and simply accept an empty value for the optional field.

Example 15: Validation events

Alpaca features an event system that triggers events like validated and invalidated when a form's validity changes. We can use these events to enable and disable external form buttons.

We can also tell Alpaca to re-run validation when the form buttons are clicked to ensure that the form is in a good state before proceeding.

Here we use a custom view to specify the layout of the form and customize the validation message. This isn't necessary but does make the example a bit more fun!