TextboxField
TextboxField
TextboxField describes a text field in a content type or global field schema, with data_type set to text. It adds a validation pattern and its error message to the properties of Field.
When to Use This Class: Use this class for a single-line textbox, a multi-line textbox, a rich text editor, or a Markdown field. Set FieldMetadata to choose between them.
Conceptual Role: Acts as the Field subclass that the SDK creates for a text field that has no enum and no dropdown or checkbox display type.
Returns: TextboxField. A text field of a schema.
Properties
TextboxField inherits every property of Field and adds the properties below.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Format | string? | No | null | Regular expression that a value must match. Serialized as format. |
| ErrorMessages | Dictionary<string, string>? | No | null | Error messages keyed by validation, for example format. Serialized as error_messages. |
Class-Level Notes
Choosing the editor.
- Set FieldMetadata.Multiline to true for a multi-line textbox, FieldMetadata.AllowRichText to true for a rich text editor, or FieldMetadata.Markdown to true for a Markdown field. See FieldMetadata.
- JsonField derives from TextboxField and describes a JSON Rich Text Editor field.
Method Index
TextboxField has no methods. Set its properties and add it to ContentModelling.Schema.
Class-Level Snippet
The snippet below creates a content type with a title field and a URL field that must start with a slash.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Fields;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ContentModelling model = new ContentModelling
{
Title = "Blog Post",
Uid = "blog_post",
Schema = new List<Field>
{
new TextboxField { DisplayName = "Title", Uid = "title", DataType = "text", Mandatory = true, Unique = true },
new TextboxField
{
DisplayName = "URL",
Uid = "url",
DataType = "text",
Format = "^/",
ErrorMessages = new Dictionary<string, string> { ["format"] = "The URL must start with a slash." },
FieldMetadata = new FieldMetadata { Instruction = "For example, /blog/my-first-post" }
}
}
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ContentType().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse()["notice"]);
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}