facet classafFormBean::Validate

  afFormBean::Validate : sys::Facet


Place on a method of a FormBean to have it take part in server side validation. Validate methods should be static and take a single FormField parameter. They should inspect the formField.value and set an errMsg if invalid. Example:

class User {
    Str? name

    @Validate { field=#name }
    static Void validateName(FormField formField) {
        if (formField.formValue == "Trisha")
            formField.errMsg = "Ex-girlfriends not allowed!"

If @Validate.field is null then the first parameter should be FormBean:

static Void validateBean(FormBean formBean) { ... }

FormBean validation is performed after FormField validation.

Note that validation methods are called using IoC, so services may be passed in as extra method parameters:

static Void validateName(FormField formField, MyService service) { ... }


const Field? field

The field this method validates. The validation method will only be called with FormFields that correspond to this field.

If null then the method will be called with a FormBean instance.