Skip to content

Latest commit

 

History

History
97 lines (71 loc) · 6.38 KB

File metadata and controls

97 lines (71 loc) · 6.38 KB

JCB! Validation Rules

What Are Validation Rules?

Validation Rules are the guardrails of every Joomla Component Builder (JCB) project.

They control data integrity, security, and business logic enforcement through the fields of your entire component.

Validation Rules ensure that what enters your system through a field is correct, expected, and trusted — before it reaches the database, file system, or application logic.

Each Validation Rule:

  • Defines how a field value is validated and when it is considered invalid
  • Can normalize or transform field data before it is accepted
  • Integrates into Joomla's form validation system at the field level
  • Is reusable across many fields, forms, and views
  • Encapsulates business rules in one central, maintainable place

Where Are Validation Rules Used in JCB?

Validation Rules in JCB link to fields, and only to fields whose fieldtypes support validation (e.g. textarea, editor, and other validation-enabled types).

Wherever that field is used in JCB, the linked Validation Rule is automatically applied:

  • Admin Forms (backend editing views)
  • Frontend Forms (site-facing input)
  • Component Configurations (parameter integrity)
  • Model Save Operations (last gate before persistence)
  • Custom Forms & Logic (where Form/JCB integration is used)

Validation Rules are not visual; they operate at the data level, wherever a field has a rule assigned.

What Can a Validation Rule Do?

A Validation Rule in JCB is a self-contained logic unit that can:

  • Enforce Data Type or Structure

    • Ensure values behave as: string, integer, float, email, url, etc.
    • Validate patterns like UUIDs, slugs, or IDs
  • Check Format & Constraints

    • Enforce minimum/maximum length
    • Restrict allowed characters (e.g., alphanumeric only)
    • Validate formats (email, URL, date-like strings, JSON-encoded structures, and more)
  • Apply Business Logic

    • Enforce that a value is unique in a specific context
    • Require that a field is only valid when another condition is met
    • Reject values that break domain-specific rules
  • Normalize / Transform Values

    • Trim whitespace
    • Convert case (lowercase/uppercase)
    • Sanitize or clean up user input before use
  • Return Clear Failure States

    • Mark the value as invalid
    • Provide a validation error message (often via language strings)
    • Prevent the form from being saved until the issue is resolved

This makes Validation Rules a powerful way to centralize and standardize how your data is allowed into the system.

Reuse and Sharing

Validation Rules are standalone, reusable entities:

  • Define a rule once → reuse across:
    • Multiple fields in the same component
    • Different views (admin/site)
    • Configuration forms and custom forms
  • Share rules by:
    • Exporting them via repositories
    • Including them in JCB-based packages
    • Syncing from remote definitions

Because JCB wires rules into generated code and XML automatically:

  • You avoid duplicating the same validation logic in multiple places.
  • You maintain consistency across forms, views, and contexts.

This reduces maintenance overhead and keeps your validation centralized and predictable.

Versioning and Customization

To update a Validation Rule:

  • Use JCB's init, reset, and push features (if you maintain rules in a repo).
  • Adjust and rebuild components to propagate changes.
  • Optionally fork a rule:
    • Create a stricter or more specialized variant.
    • Keep legacy behavior for older fields while newer fields use the updated rule.

Validation Rules turn raw input into reliable data — they ensure that every saved value respects the rules of your domain.


Index of Validation Rules


Joomla Volunteer Portal Octoleo Llewellyn Telegram Mastodon X (Twitter) GitHub YouTube n8n Docker Hub Open Collective GPG Key