Text Field
Single-line text input field for basic text entry
The Text Field component provides a single-line text input for collecting basic text data from users. It's the most commonly used field type for names, titles, and short text entries.
Basic Usage
Basic Text Field
With Placeholder
With Placeholder
Required Field
Required Field
Read-Only
Read Only Field
Field Schema
A text field is authored as TextFieldMetadata (@object-ui/types), which is the
source of truth for the key set: it extends BaseFieldMetadata with the
text-specific validation keys. The length bounds are @objectstack/spec's own
FieldSchema.minLength / maxLength, typed by reference; the snake_case
min_length / max_length are retired, refused by the spec by name and read by
nothing.
import type { TextFieldMetadata } from '@object-ui/types';
const productName: TextFieldMetadata = {
type: 'text',
name: 'product_name',
label: 'Product Name',
placeholder: 'Enter a product name',
inlineHelpText: 'Shown on the storefront and in search results.',
required: true,
minLength: 2,
maxLength: 120,
};Format Validation
A regex check is declared on the object, not on the field. @objectstack/spec
has a validation rule for it: an entry of the object definition's validations[]
whose type is 'format'. For the field above it carries:
name: the rule's own snake_case name, e.g.'product_name_characters';field: the field it checks,'product_name';regex:'^[A-Za-z0-9 -]+$'. It is not anchored for you, so write^and$to match the whole value;message:'Letters, digits, spaces and hyphens only.', the reason given when the value is refused.
The server runs the rule on every write that touches the field and refuses a
non-empty value the regex does not match, with the rule's message. FieldSchema
has no field-level pattern or pattern_message: it refuses both by name, and
TextFieldMetadata refuses them at compile time.
The form does not pre-check this rule in the browser. A value that breaks it is
refused when the record is saved, and the rule's message is the reason given.
The value being edited, and the className / disabled a host supplies, are not
metadata keys — they are runtime widget props. See Field Widget Props.
Use Cases
- User Names: Collecting first names, last names, or usernames
- Titles: Post titles, document names, or product names
- Short Text: Any short text input that doesn't require multiple lines
- IDs: Custom identifiers or reference numbers
Cell Renderer
When used in data tables or grids, the text field is rendered as simple truncated text:
import { TextCellRenderer } from '@object-ui/fields';
// Automatically used for type: 'text' in grids/tables
// Displays value or '-' if empty