Skip to content

View field

ViewField is the escape hatch for read-only custom markup inside a schema. .content() accepts a string or callable evaluated with state and render context. Defaults _dehydrated = False. Content is inserted into or-view-field without automatic escaping when you return HTML from a callable — sanitize untrusted data yourself. For interactive controls, subclass Field instead (see Custom fields).

Each variation below includes a detailed explanation, the fluent API to paste into your schema, and light/dark screenshots of the rendered control.

Static HTML summary with a label.

app/orbit/resources/example_resource.py
ViewField.make('summary')
.label('Summary')
.content('<strong>3</strong> open invoices')

Orbit Basic view field (light)

Orbit Basic view field (dark)

Build markup from record/state at render time. Return a safe HTML string.

app/orbit/resources/example_resource.py
ViewField.make('balance')
.label('Balance')
.content(lambda state=None, record=None, **_: f'<span class="or-money">{state or 0}</span>')

Orbit Callable content (light)

Orbit Callable content (dark)

Use .visible() closures to omit the field when there is nothing to show.

app/orbit/resources/example_resource.py
ViewField.make('warning')
.label('Warning')
.content(lambda record=None, **_: getattr(record, 'warning_html', ''))
.visible(lambda record=None, **_: bool(getattr(record, 'warning_html', None)))

Orbit Hidden when empty (light)

Orbit Hidden when empty (dark)

If you need the view payload in dehydrated state (for example a signed summary string), opt into dehydration.

app/orbit/resources/example_resource.py
ViewField.make('checksum')
.label('Checksum')
.content(lambda state=None, **_: state or '')
.dehydrated(True)

Orbit Dehydrated view value (light)

Orbit Dehydrated view value (dark)

Closures work on .label(), .helper_text(), .placeholder(), .visible(), .disabled(), and .required() where applicable — see Form closures.