Fields

Code Field

The code field renders a CodeMirror-based code editor with syntax highlighting in the admin UI and stores the content as a plain string. Use this field for code snippets, configuration files, templates, or any content that benefits from syntax-aware editing.

The underlying Convex validator is v.string(), wrapped in v.optional() unless marked as required.

Config options

OptionTypeRequiredDefaultDescription
requiredbooleanfalseMakes the field required in the schema and admin UI
readOnlybooleanfalseRenders the editor as non-editable
placeholderstringPlaceholder text shown when the editor is empty
labelstring | functionField nameCustom label for the admin UI
descriptionstringHelp text displayed below the field label
languageCodeLanguage | "auto""plaintext"Programming language for syntax highlighting
lineNumbersbooleantrueShow line numbers in the gutter
heightnumber200Editor height in pixels
wordWrapbooleanfalseEnable word wrapping for long lines
tabSizenumber2Number of spaces per tab
copyButtonbooleanfalseShow a copy-to-clipboard button on hover
conditionFieldConditionCondition for showing or hiding this field
sidebarbooleanfalsePlace this field in the document sidebar

Supported languages

The language option accepts any of the following values:

javascript, typescript, json, html, css, scss, markdown, yaml, xml, sql, graphql, python, ruby, go, rust, java, php, c, cpp, csharp, shell, plaintext

Set language to "auto" to attempt automatic language detection from the content.

Example usage

import { f, defineVextroCollection } from "vextro";

export const snippets = defineVextroCollection({
  slug: "snippets",
  label: "Code Snippets",
  collectionType: "content",
  tableName: "snippets",
  fields: {
    title: f.text({ required: true }),
    language: f.select({
      options: ["typescript", "javascript", "python", "go", "rust"],
      required: true,
    }),
    code: f.code({
      required: true,
      language: "typescript",
      lineNumbers: true,
      height: 400,
      tabSize: 2,
      description: "Paste or write your code snippet here",
    }),
    embedCode: f.code({
      language: "html",
      height: 150,
      wordWrap: true,
      label: "Embed HTML",
    }),
    config: f.code({
      language: "yaml",
      lineNumbers: false,
      height: 200,
      label: "YAML Config",
    }),
  },
});

Admin options

The editor adapts its syntax highlighting and auto-completion behavior based on the configured language. The height option controls the initial editor height in pixels; editors are scrollable when content exceeds this height. Line numbers are enabled by default and can be hidden with lineNumbers: false for compact display.

Conditional display

customCss: f.code({
  language: "css",
  label: "Custom CSS",
  condition: { field: "enableCustomStyles", equals: true },
  height: 300,
})
Previous
JSON
Next
Color