Examples

Content entry form

Built with the mantine-form skill

Create content entry

Blog post

0 / 120

Shown in previews

0 / 240

Link to other content

Body

Drag an image here or click to select

One image

Drag a file here or click to select

One file

Build a form for creating a content entry from a content model in a headless CMS. The component receives the model (name, key, ordered fields with their options, as produced by the content model editor) and builds the whole form from it: inputs, initial values and validation all come from the schema, nothing is hard-coded per model.

Entry:

  • content key (required, typed by the user, lowercase letters, digits and dashes)
  • language (required, select from en-US, de-DE, fr-FR, es-ES; default en-US)
  • tags (tags input with 5 suggested tags to pick from and free-form input, up to 10, no duplicates)

Fields, in model order, with label and description from the field and required when the field is required:

  • Text: single-line input or textarea depending on the field's display setting, max length from the field with a counter, default value pre-filled
  • Rich text: rich text editor (@mantine/tiptap) with bold, italic, headings, lists and links; required means non-empty content
  • Boolean: checkbox with the field's default
  • JSON: textarea validated as JSON, pretty-printed on blur, default pre-filled
  • Select: select with the field's options and default
  • Image: dropzone (@mantine/dropzone) accepting images only, one file, with a preview of the chosen image and a way to remove it
  • File: dropzone accepting any file, one file, showing the file name and size and a way to remove it
  • Reference: an input that opens a modal to pick entries from a hard-coded list of entries (key, title, model); the input looks like a multi select: selected entries as removable pills inside it, a placeholder when empty; the modal has a search input and, when the field's target model is not fixed, a filter by model; single or multiple selection according to the field; entries are identified by key: the key is the primary text of every entry in the picker and in the pills, title and model are secondary

Validation:

  • built from the schema: each field type has its own validator (required, max length, valid JSON, image mime type, at least one reference when required, …), composed per field from its options
  • the entry key and language are validated like any other field

Behavior:

  • two hard-coded example models (Blog post, Landing page hero) with a model switcher above the form; switching the model rebuilds the form with that model's fields and defaults
  • submit validates everything and focuses the first invalid field
  • on submit show a short notification (entry key and model name), display the entry JSON (key, language, tags, model key, values keyed by field key) under the form and keep the form as is

Write tests for the component.