Validation Registry (@dfbe/core/registry)
The @dfbe/core/registry entry point provides builder metadata — static data structures describing what validation rules are available for each field type. This is designed for use in admin tools (like the Studio's Property Panel) rather than in production forms.
1. VALIDATION_REGISTRY
The central registry mapping each ValidationCategory to its human-readable label and list of configurable rules.
import { VALIDATION_REGISTRY } from "@dfbe/core/registry";
Structure
VALIDATION_REGISTRY: Record< ValidationCategory, { label: string; rules: ValidationRuleDefinition[] } >;
ValidationCategory values
| Category | Description | Applied to field types |
|---|---|---|
string | Text-based input | text, textarea, email |
number | Numeric input | number |
array | Multi-select | checkbox-group |
boolean | Single checkbox | checkbox |
date | Date picker | date |
selection | Single-select (no extra rules) | select, combobox, searchable-select, radio |
file | File upload | file |
ValidationRuleDefinition shape
Each entry in rules has the following properties:
| Property | Type | Description |
|---|---|---|
key | string | The property name in the JSON schema (e.g. "minLength"). |
label | string | Human-readable label for the UI editor (e.g. "Minimum Length"). |
inputType | "number" | "text" | "boolean" | "select" | What kind of input to render in the Property Panel. |
defaultMessage | string | Default error message template. Use {val} as placeholder for the rule value. |
description | string | Optional tooltip text for the editor. |
options | string[] | Options list, only used when inputType is "select". |
Example: Building a Property Panel
import { VALIDATION_REGISTRY, FIELD_TYPE_CATEGORY_MAP } from "@dfbe/core/registry"; import type { FieldType } from "@dfbe/core"; function ValidationEditor({ fieldType }: { fieldType: FieldType }) { const category = FIELD_TYPE_CATEGORY_MAP[fieldType]; if (!category) return null; // e.g. markdown fields have no validation const { label, rules } = VALIDATION_REGISTRY[category]; return ( <section> <h4>{label}</h4> {rules.map((rule) => ( <div key={rule.key}> <label title={rule.description}>{rule.label}</label> {rule.inputType === "boolean" && <input type="checkbox" />} {rule.inputType === "number" && <input type="number" />} {rule.inputType === "text" && <input type="text" />} </div> ))} </section> ); }
2. FIELD_TYPE_CATEGORY_MAP
Maps every FieldType to its corresponding ValidationCategory (or null for types with no validation).
import { FIELD_TYPE_CATEGORY_MAP } from "@dfbe/core/registry";
Full Mapping
| Field Type | Validation Category |
|---|---|
text | string |
textarea | string |
email | string |
number | number |
select | selection |
combobox | selection |
searchable-select | selection |
radio | selection |
checkbox | boolean |
checkbox-group | array |
date | date |
file | file |
markdown | null (no validation) |
Usage
const category = FIELD_TYPE_CATEGORY_MAP["number"]; // "number" const rules = VALIDATION_REGISTRY["number"].rules; // [{ key: "min", ... }, { key: "max", ... }, { key: "multipleOf", ... }, ...]
3. Available Rules Per Category
string Rules (for text, textarea, email)
| Key | Input Type | Default Message |
|---|---|---|
minLength | number | Minimal {val} karakter |
maxLength | number | Maksimal {val} karakter |
regex | text | Format tidak valid |
email | boolean | Format email tidak valid |
startsWith | text | Harus diawali dengan {val} |
endsWith | text | Harus diakhiri dengan {val} |
includes | text | Harus mengandung {val} |
ignoreCase | boolean | (modifier — no error message) |
number Rules
| Key | Input Type | Default Message |
|---|---|---|
min | number | Minimal bernilai {val} |
max | number | Maksimal bernilai {val} |
minLength | number | Minimal terdiri dari {val} digit |
maxLength | number | Maksimal terdiri dari {val} digit |
multipleOf | number | Harus kelipatan {val} |
startsWith | text | Harus diawali dengan {val} |
endsWith | text | Harus diakhiri dengan {val} |
includes | text | Harus mengandung {val} |
array Rules (for checkbox-group)
| Key | Input Type | Default Message |
|---|---|---|
minItems | number | Pilih setidaknya {val} opsi |
maxItems | number | Pilih maksimal {val} opsi |
requireAllChecked | boolean | Harap centang semua opsi |
date Rules
| Key | Input Type | Default Message |
|---|---|---|
minDate | text | Tanggal minimal adalah {val} |
maxDate | text | Tanggal maksimal adalah {val} |
boolean Rules (for checkbox)
No extra rules. Only required applies — enforces that the checkbox must be checked.
selection Rules (for select, combobox, searchable-select, radio)
No extra rules. Only required applies — enforces that a value must be selected.
file Rules
| Key | Input Type | Default Message |
|---|---|---|
maxFileSize | number | Ukuran file tidak boleh melebihi {val} MB |
accept | text | Format file tidak diizinkan. Harus berupa: {val} |
4. Design Notes
- This module is intentionally separate from the main engine bundle (
@dfbe/core). It is never imported byFormEngineProviderorFieldRenderer, keeping the production runtime lean. - The registry is static and does not change at runtime. It is safe to call at module initialization time.
ignoreCaseis a modifier that affects howstartsWith,endsWith, andincludesare evaluated — it does not produce its own error message.