webiny-api-cms-custom-field-type

Implements custom CMS field types for Webiny's model builder fluent API.

8.0k|673|Updated Jan 9, 2018
One-click install
npx skills add https://github.com/webiny/webiny-js --skill webiny-api-cms-custom-field-type
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: webiny-api-cms-custom-field-type
Source: https://github.com/webiny/webiny-js/tree/main/skills/user-skills/api/custom-field-type
Command: npx skills add https://github.com/webiny/webiny-js --skill webiny-api-cms-custom-field-type

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Webiny's built-in CMS field types (text, number, boolean, datetime, file, ref, object, richText, longText, json, dynamicZone) cannot cover every storage format or validation rule a project needs. This Skill guides you through creating a custom field type that plugs into the model builder's fluent API with full TypeScript autocomplete.

Core Features & Use Cases

  • Custom Field Builder: Extend DataFieldBuilder<"yourType"> and compose FieldTypeValidator interfaces (required, pattern, unique, minLength, etc.) to expose chainable validator methods.
  • DI Registration: Create a FieldType.Factory implementation and register it in the Webiny DI container via createFeature, so the FieldBuilderRegistry picks it up at construction time.
  • TypeScript Autocomplete: Use module augmentation on "webiny/api/cms/model" so fields.slug() (or your own type) appears in the fields() registry with typed signatures.
  • Use Case: You need a slug field with lowercase pattern validation and uniqueness enforcement. This Skill walks you through building SlugFieldBuilder, its factory, and registering it so any ModelFactory can call fields.slug().required().unique().pattern("^[a-z0-9-]+$").

Quick Start

Ask the AI to create a custom CMS field type (for example a slug field) for Webiny following the DataFieldBuilder and FieldType.Factory pattern, including DI registration and module augmentation.

Frequently Asked Questions about webiny-api-cms-custom-field-type

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a custom field type in Webiny CMS?

Create a builder class extending DataFieldBuilder with your unique type string, implement validator methods that call this.validation(), then write a factory class implementing FieldType.Factory. Register the factory with container.register() inside a createFeature module.

How to add TypeScript autocomplete for a custom Webiny field type?

Use module augmentation on the "webiny/api/cms/model" module and extend the IFieldBuilderRegistry interface with a method like slug(): ISlugFieldBuilder. After registration, fields.slug() gets full typing in any ModelFactory implementation.

What validators can I add to a custom Webiny CMS field?

You can compose FieldTypeValidator interfaces including Required, Unique, MinLength, MaxLength, Pattern, Email, Url, LowerCase, UpperCase, Gte, Lte, DateGte, DateLte, ListMinLength, and ListMaxLength. Each adds one typed method to your builder interface.

Can a custom Webiny field type reuse built-in type names?

No. The factory's readonly type string must be unique and cannot collide with built-in types like text, number, boolean, datetime, file, ref, object, richText, longText, json, or dynamicZone, nor with other custom types.

Why is my custom Webiny field type not appearing in the model builder?

The FieldBuilderRegistry collects all FieldType instances at construction time, so your factory must be registered in the DI container before the registry is resolved. Register it in the same register() call or earlier, and verify the module augmentation targets "webiny/api/cms/model".