Code#

Code holds source text (a snippet of HTML or CSS, a query, a configuration), code in the descriptor. It keeps the text in a string property (a TEXT column, as a Text field would) and edits it in a code editor that highlights its language():

Code::make('routingRules', 'Routing rules')->language('yaml')->rows(8),
A Code field on a support team's form: the Routing rules editor with line numbers and YAML highlighting, and its help text below
A Code field on a support team's form: the Routing rules editor with line numbers and YAML highlighting, and its help text below

Option

Effect

language()

The highlighting: plain (the default, none), json, html, css, javascript, typescript, sql, php, yaml, markdown or xml. Any other name is refused when the field is defined.

lineNumbers(false)

Turns the gutter’s line numbers off, for a short snippet. They are on by default.

rows(n)

How many lines the editor shows before it scrolls, 2 to 40 (10 by default).

None of them changes what is stored: on the wire the value is the text as typed, whitespace included, and the server validates it as text (required(), max(), rule()), never as the language. It sorts, filters and searches as a text column does, and is not edited inline. A list shows its first line in monospace, shortened; the record page shows it highlighted in a read-only editor.

The editor follows the light and dark theme, is read-only for a readonly() field and in a disabled form, and shows a violation on its frame like any input. Tab moves to the next field, as it does everywhere else in the form, and the editor is labelled by the field’s label. Code reads left to right in a right-to-left layout too. The editor and each language’s highlighting load only when a form or a record first shows one, so pages without a code or JSON field never download them.

It takes the common modifiers too.