Skip to content

Validation

Each Box config can define custom validation rules. These rules will be applied to the form in the Boxes editor.

To define custom validation rules, simply add a validation key to a Box config.

You can now define rules, attributeNames and customMessages to be used in October's Validation trait.

yaml
validation:
    rules:
        title:
            - required
            - numeric
            - "min:15"
    attributeNames:
        title: Title
    customMessages:
        title.min: "The title has to be at least 15 characters long"

Referencing other fields in validation rules

Boxes saves all Box data under a jsonable data column in the database.

This requires you to reference any other field name in your validation rules with the data. prefix:

Note, that the default relations (image, file, images, files) are not prefixed.

yaml
validation:
    rules:
        title:
            # Note the `data` prefix
            - required_if:data.type,1

form:
    fields:
        type:
            label: Type
            type: dropdown
            options:
                1: Title required
                2: Title optional
        title:
            label: Title
            type: text