Skip to main content

TextField

Displays a string value, optionally framed by a prefix and a postfix.

It is the fallback for every string field without a more specific format. For a fixed set of values use ChoicesField; for pre-rendered HTML use format: "rich-text", which maps to React Admin's RichTextField.

Example​

<TextField source="sku" prefix="#" />
<TextField source="description" multiline />

Props​

On top of multiline the component accepts the shared field props.

NameTypeDefaultDescription
source (required)string—Name of the field on the record
multilinebooleanfalse in a list, true elsewhereKeeps line breaks (white-space: pre-wrap) instead of collapsing the value onto one line
emptyTextstring—Text shown when the value is empty
prefixstring—Muted text before the value
postfixstring—Muted text after the value

The schema layer maps options.prefix / options.postfix onto the props above, and turns multiline on for format: "text", before rendering this component directly.

The value — or emptyText when the value is empty — is truncated with an ellipsis when it does not fit its container. When the record came from a fulltext search, the matched part of the value is highlighted automatically.

Schema mapping​

Any string field without a recognised format, plus format: "text" which turns multiline on:

{"name": "description", "type": "string", "format": "text"}

TextField and RichTextField from habarico.serializers set the format explicitly; a plain CharField/TextField on the model maps to a bare string:

from habarico.serializers import AdminModelSerializer, TextField


class ProductSerializer(AdminModelSerializer):
description = TextField()

class Meta:
model = Product
fields = ["id", "name", "description"]

See also​