Skip to content
D
Documentation

PropertyValidation

reference
1 min readUpdated

Import it from @grafloria/renderer.

Validation rules for property values

ts
interface PropertyValidation

Properties

NameTypeDefaultDescription
required?booleanWhether the property is required
minLength?numberMinimum string length (for string properties)
maxLength?numberMaximum string length (for string properties)
pattern?stringRegular expression pattern (for string properties)
min?numberMinimum value (for number properties)
max?numberMaximum value (for number properties)
step?numberStep increment (for number properties)
integer?booleanWhether the number must be an integer (for number properties)
enum?any[]Allowed values (for select/multiselect properties)
options?SelectOption[]Options for select/multiselect (alternative to enum with more control)
jsonSchema?anyJSON Schema for validating JSON properties
placeholder?stringPlaceholder text for input fields
prefix?stringPrefix text to display before input (e.g., "$" for currency)
suffix?stringSuffix text to display after input (e.g., "px" for pixels)
presets?string[]Preset color values for color picker
accept?stringAccepted file types (for file uploads)
multiple?booleanAllow multiple file selection
maxSize?numberMaximum file size in bytes
custom?(value: any, allValues: Record<string, any>) => ValidationError | nullCustom validation function

Example

String validation

typescript
const validation: PropertyValidation = {
  required: true,
  minLength: 3,
  maxLength: 50,
  pattern: '^[a-zA-Z]+$'
};

Example

Number validation

typescript
const validation: PropertyValidation = {
  required: true,
  min: 0,
  max: 100,
  step: 5
};

Example

Custom validation

typescript
const validation: PropertyValidation = {
  custom: (value, allValues) => {
    if (value < allValues.minValue) {
      return { message: 'Must be greater than minimum' };
    }
    return null;
  }
};

Was this page helpful?

PropertyValidation — Grafloria