String
A schema type for strings and a selectable lists of strings.

Short string. Typically used for titles, names, and labels. If you need a basic multi-line string input, use the text
. If you need text with markup and structured data, use block
.
Properties
Requiredtype
Required. Value must be set to
string
.
Requiredname
Required. The field name. This will be the key in the data record.
title
Human readable label for the field.
If set to
true
, this field will be hidden in the studio. You can also return a callback function to use it as a conditional field.
readOnly
If set to
true
, this field will not be editable in the content studio. You can also return a callback function to use it as a conditional field.
description
Short description to editors how the field is to be used.
initialValue
The initial value used when creating new values from this type. Can be either a literal string value or a resolver function that returns either a literal string value or a promise resolving to the initial string value.
deprecated
Marks a field or document type as deprecated in the studio interface and displays a user-defined message defined by the single required
reason
property.If you deploy a GraphQL API schema, this property will translated into the
@deprecated
directive.
Options
list
A list of predefined values that the user can choose from. The array can either include string values
['sci-fi', 'western']
or objects[{title: 'Sci-Fi', value: 'sci-fi'}, ...]
.String values will automatically be made uppercase in the Studio. To prevent this, use object values instead.
layout
Controls how the items defined in the
list
option are presented. If set to'radio'
the list will render radio buttons. If set to'dropdown'
you'll get a dropdown menu instead. Default isdropdown
.
direction
Controls how radio buttons are lined up. Use
direction: 'horizontal|vertical'
to render radio buttons in a row or a column. Default isvertical
. Will only take effect if thelayout
option is set toradio
.
Validation
required()
Ensures that this field exists.
min(minLength)
Minimum length of string.
max(maxLength)
Maximum length of string.
length(exactLength)
Exact length of string.
uppercase()
All characters must be uppercase.
lowercase()
All characters must be lowercase.
email()
Value must be a valid email-address.
regex(pattern[, options])
String must match the given pattern.
options
is an optional object, currently you can setoptions.name
andoptions.invert
.Providing a
name
will make the message more understandable to the user ("Does not match the <name>-pattern").Set
invert
totrue
in order to allow any value that does NOT match the pattern.
custom(fn)
Creates a custom validation rule.
Examples
Field configuration
{
title: 'Title',
name: 'title',
type: 'string',
description: 'Make it catchy',
validation: Rule => Rule.max(120).warning(`A title shouldn't be more than 120 characters.`)
}
List of predefined strings
Input
{
title: 'Genre',
name: 'genre',
type: 'string',
options: {
list: [
{title: 'Sci-Fi', value: 'sci-fi'},
{title: 'Western', value: 'western'}
], // <-- predefined values
layout: 'radio' // <-- defaults to 'dropdown'
}
}
Response
{
"_type": "movie",
"_id": "23407q-qwerqyt12",
"genre": "sci-fi",
...
}
Protip
Want to make a multi-select for strings? Check out the Array schema type to see how you can build an array of strings, references, objects, and more.
For details on how to access the title
value of a list in your document list preview, please see the documentation on previewing from predefined string lists.
Setting initial value for string fields
You can use initial values to preset string fields on document creation:
export default {
name: 'post',
type: 'document',
title: 'Post',
initialValue: {
title: 'The initial title'
},
fields: [
{
name: 'title',
type: 'string',
title: 'Title'
}
]
}
Was this page helpful?