Validation

This is the official documentation of Forest Admin Cloud.

Most data sources can import validation rules directly. For example, in a SQL database, columns defined as VARCHAR(15) will automatically include a rule to ensure content is shorter than 15 characters. Similarly, columns marked as NOT NULL will require that some content is always present.


To make the code easier to read, all the code snippets below should be wrapped in the following code. Ensure you update the collection and field names as needed.

import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  agent.customizeCollection('users', (collection) => {
    // Insert the code snippet here.
  });
}

In some cases, it might be necessary to enforce stricter rules than the ones currently set in your data source. This can be achieved through the use of the addFieldValidation method.

collection
  .addFieldValidation('first_name', 'Present')
  .addFieldValidation('first_name', 'LongerThan', 2)
  .addFieldValidation('first_name', 'ShorterThan', 13)
  .addFieldValidation('first_name', 'Match', /^[a-z]+$/i);

Last updated