Skip to main content
The editor field stores HTML-formatted text content, typically from rich text editors like TinyMCE. It validates content size and provides options for URL conversion handling.

Configuration options

maxSize
int64
default:"5242880"
Maximum size of the content in bytes (up to 2^53-1). Defaults to ~5MB if not set or zero.
convertURLs
bool
default:"false"
Hint for the editor whether to apply URL conversion (e.g., stripping the domain name if URLs use the same domain as the editor). This is primarily used by the frontend editor component.
required
bool
default:"false"
When true, requires the field value to be a non-empty string.

Validation rules

The editor field validates:
  • Type: Value must be a string
  • Size: Content size must not exceed maxSize bytes
  • Required: If enabled, value cannot be empty
The editor field does NOT perform HTML sanitization or validation. You should sanitize HTML content in your application layer if storing user-generated content.

Go examples

import "github.com/pocketbase/pocketbase/core"

field := &core.EditorField{
    Name:     "content",
    Required: true,
}

collection.Fields.Add(field)

// Set HTML content
record.Set("content", "<h1>Article Title</h1><p>Article content here...</p>")

Database column type

TEXT DEFAULT '' NOT NULL

Frontend integration

The convertURLs option is used by frontend editors like TinyMCE:
tinymce.init({
    selector: '#editor',
    convert_urls: record.convertURLs, // From field config
    // Other TinyMCE options...
});

Common use cases

field := &core.EditorField{
    Name:     "body",
    Required: true,
    MaxSize:  10 << 20, // 10MB
}

HTML sanitization

The editor field does not sanitize HTML. You should implement sanitization in your application:
import "github.com/microcosm-cc/bluemonday"

func sanitizeHTML(html string) string {
    p := bluemonday.UGCPolicy()
    return p.Sanitize(html)
}

// Before saving
cleanHTML := sanitizeHTML(userInput)
record.Set("content", cleanHTML)

Handling images and files

When storing HTML with embedded images, you have several options:
<!-- Upload images to a file field first -->
<img src="/api/files/articles/RECORD_ID/image.jpg" alt="Article image" />
Avoid storing large base64-encoded images in editor fields as they significantly increase field size. Instead, use a separate file field and reference the URLs.

Best practices

  • Set appropriate maxSize based on expected content length
  • Implement HTML sanitization to prevent XSS attacks when storing user content
  • Use file fields for images and reference them in HTML
  • Consider separating very long content into multiple fields
  • For plain text editors, use the text field instead
  • The convertURLs option is a UI hint; it doesn’t modify stored data
  • Consider implementing content versioning for important editable content

Content size estimation

HTML content size includes all tags and attributes:
  • Plain text: ~1 byte per character
  • HTML tags add overhead: <p>text</p> is 12 bytes total
  • Embedded styles and scripts significantly increase size
  • Base64 images are ~33% larger than binary equivalents
Plan your maxSize accordingly!

Zero value

The zero value for editor fields is an empty string "".