Array field with required sub-properties.
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.
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!