Admin panel
Validation and conditions
A column’s rules are declared once, on the column, and enforced by the server on every write that reaches the API. The CMS reads the same rules from the table’s descriptor and checks them in the form before it saves, so an operator sees the error on the field, not as a refused request.
// backend/schema/events.tsimport { defineTable, col } from "@rebasepro/server/schema";
export const events = defineTable("events", { columns: { id: col.uuid().primaryKey().defaultRandom(), title: col.text().notNull().validate({ min: 2, max: 200, requiredMessage: "Every event needs a title" }), slug: col.varchar({ length: 80 }).notNull().unique() .validate({ matches: "^[a-z0-9-]+$", matchesMessage: "Lowercase letters, digits and hyphens only" }), isFree: col.boolean().notNull().default(false), price: col.numeric({ precision: 10, scale: 2 }).validate({ min: 0 }), seats: col.integer().validate({ positive: true }), }, rls: "admin-only",});What the form checks
Section titled “What the form checks”| On the column | In the form |
|---|---|
.notNull() |
Required, with requiredMessage as the error when given. Not required where nobody types the value: a generated key, a stamp, a generated or .readOnly() column. |
.unique() |
The value is checked against the table before a changed value is saved, and a duplicate is named on its field. |
varchar(n), char(n) |
At most n characters. |
text min, max, length |
Character counts, inclusive. |
matches, matchesMessage |
The whole value must match the pattern; the message is the error. |
email, url |
The value must be an email, a URL. |
trim, lowercase, uppercase |
The value is trimmed or case-folded before it is saved. |
number min, max, moreThan, lessThan, positive, negative, integer |
Bounds, and whole numbers only. Integer and serial columns are whole numbers whatever .validate() says. |
date min, max |
The earliest and latest accepted date. |
array minItems, maxItems, uniqueItems |
How many items, and no item twice. |
Every rule is listed, with its exact meaning, on Columns.
Where validation runs
Section titled “Where validation runs”The server checks a column’s rules at the request boundary (REST, the realtime
socket and MCP) on what the caller sent, before beforeSave runs, and answers a
write that breaks a rule with a 400 naming every failing field. Server code that
writes in-process is trusted and is not checked against these rules; what holds
there is what the database enforces. See
Columns.
The CMS checks the same rules before it saves, in the record form and in the table’s inline editor. A table cell judges a value once you edit it: a stored value that breaks a rule added later shows no error until someone edits that cell.
Conditional fields
Section titled “Conditional fields”A field can react to the record’s own values: become required, disabled,
read-only or hidden. There are two ways, both in customizeTable:
// frontend/src/cms/events.tsximport { customizeTable } from "@rebasepro/cms";import type { events } from "../../../backend/schema/events";
export const eventsCms = customizeTable<typeof events>("events", { fields: { price: { conditions: { disabled: { "==": [{ "var": "values.isFree" }, true] }, required: { "!=": [{ "var": "values.isFree" }, true] }, min: 0, disabledMessage: "Free events have no price", clearOnDisabled: true, }, }, seats: { dynamicProps: ({ values, authController }) => ({ disabled: values.isFree === true || !authController.user?.roles?.includes("admin"), }), }, },});conditions: JSON Logic
Section titled “conditions: JSON Logic”conditions holds JSON Logic rules over the record
being edited (values.<key>). They are data, so the schema editor can read and
change them. A condition can set:
disabled,disabledMessage,clearOnDisabled,hidden,readOnly;required,requiredMessage,min,max;defaultValue;enumConditions,allowedEnumValues,excludedEnumValues;referencePath,referenceFilter;canAddElements,sortable, for arrays.
disabledMessage is what the reader sees beside the greyed-out control. Without
it a disabled field explains nothing.
dynamicProps: a function
Section titled “dynamicProps: a function”dynamicProps is handed the record as it is being edited (values, unsaved
edits included, and previousValues once it is saved) with the signed-in user
on authController, and returns the field options that apply now. What it
returns is applied over the field’s other options each time the form asks, so it
can return any field option: disabled, hidden, readOnly, name,
description, enumLabels…
Labels for a closed set
Section titled “Labels for a closed set”The values of a col.enum([...]) or a .oneOf([...]) are the column’s. Their
labels, colours and order are the CMS’s, set with enumLabels and enumOrder;
see closed sets.
Next steps
Section titled “Next steps”- Columns: every validation rule
- Fields: the fields these rules apply to
- Row-level security: the rules the database enforces, which validation does not replace