Text
Schema type reference for the Text type.
A string expected to contain multiple lines, rendered as a textarea. Typically used for a summary or a short bio. If you need rich text with markup and structured data, use block text.
A text field stores a string, but it is its own schema type rather than a subtype of string. That distinction decides which options the studio honors. See the TextDefinition reference for the full type definition.
Properties
Requiredtype
Value must be set to
text.Requiredname
The field name. This becomes the key in the document.
Controls how many rows the rendered textarea shows. Defaults to
10.Human-readable label for the field.
If set to
true, this field is hidden in the studio. You can also supply a callback function to make it a conditional field.If set to
true, this field is not editable in the studio. You can also supply a callback function to make it a conditional field.Short description for editors of how the field is to be used.
The initial value used when creating new values of this type. Can be a literal value, or a resolver function that returns a literal value or a promise that resolves to one.
Lets you provide custom components to override the studio defaults in various contexts. The available keys are
diff,field,input,item, andpreview.Marks a field or document type as deprecated in the studio interface and displays a user-defined message set through the single required
reasonproperty.If you deploy a GraphQL API schema, this property is translated into the
@deprecateddirective.Supply a custom icon for this field. See the icons documentation for more information.
Placeholder text shown in the input when it has no value.
Options
Text fields accept the shared options below. See the TextOptions reference for the full type definition.
Sets a search weight for this field so that it ranks higher when editors search in the studio. Takes
{weight: number}. Text fields are searchable because they store a string. The default weight is1.Configures how Sanity Create interfaces with this field. Set
exclude: trueto leave the field out of Sanity Create, orpurposeto describe what the field holds so that content mapping can use it.Configures how Canvas interfaces with this field. Takes the same
excludeandpurposeproperties assanityCreate.
Gotcha
TextOptions extends StringOptions in the TypeScript types, so list, layout, and direction type-check on a text field. The studio ignores them, because it resolves the list input only for types that derive from string, and text does not. Use string with options.list if you need a predefined list.
defineField({
name: 'summary',
type: 'text',
rows: 3,
options: {search: {weight: 5}},
})Validation
Chain these methods on the rule passed to validation. See the TextRule reference for the full type definition.
Ensures that this field exists.
Discards the validation rules set before it in the chain and makes the field optional. Rules chained after it still apply.
Minimum length of string.
Maximum length of string.
Exact length of string.
All characters must be uppercase.
All characters must be lowercase.
Value must be a valid email address.
String must match the given pattern.
nameandoptionsare both optional, andnamecan be passed either positionally or asoptions.name.Providing a name makes the message more understandable to the editor (Does not match the <name>-pattern).
Set
options.inverttotrueto allow any value that does not match the pattern.Creates a custom validation rule.
Sets a custom error message for the preceding validation rule.
Sets a custom warning message for the preceding validation rule. Warnings do not prevent publishing.
Sets a custom info message for the preceding validation rule. Info messages are purely informational and do not prevent publishing.
Gets the value of a sibling field to use in validation. Useful for creating validation rules that depend on the value of another field.
Input
import {defineField, defineType} from 'sanity'
export const movie = defineType({
name: 'movie',
type: 'document',
fields: [
defineField({
name: 'description',
type: 'text',
rows: 4,
validation: (rule) => rule.max(500),
}),
],
})Response
{
"_type": "movie",
"_id": "23407q-qwerqyt12",
"description": "...rather long text here....\n yes.. long",
...
}