FieldMetadata
FieldMetadata
FieldMetadata holds the extra settings of a Field, such as a default value, a placeholder, instructions for editors, and the type of rich text editor.
When to Use This Class: Use this class to set the FieldMetadata property of a field. For example, it turns a text field into a rich text editor, or gives a field a default value.
Conceptual Role: Acts as the data model that a field serializes under the field_metadata key.
Returns: FieldMetadata. The extra settings of a field.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Default | JsonElement? | No | null | Default setting, which the API returns as a boolean or a string. Serialized as _default. |
| DefaultValue | object? | No | null | Default value of the field. Serialized as default_value. |
| AllowRichText | bool | No | false | Turns a text field into a rich text editor. Serialized as allow_rich_text. |
| Description | string? | No | null | Description of the field. Serialized as description. |
| Multiline | bool | No | false | Turns a text field into a multi-line textbox. Serialized as multiline. |
| RichTextType | string? | No | null | Editor type, for example basic, custom, or advanced. Serialized as rich_text_type. |
| Options | List<string>? | No | null | Toolbar options of a custom rich text editor. Serialized as options. |
| Version | int | No | 0 | Rich text editor version: 1 for the older editor, 3 for the latest. Serialized as version. |
| Markdown | bool | No | false | Turns a text field into a Markdown field. Serialized as markdown. |
| Placeholder | string? | No | null | Hint text shown in an empty input. Serialized as placeholder. |
| Instruction | string? | No | null | Help text shown below the field. Serialized as instruction. |
| RefMultiple | bool | No | false | Lets a reference field hold more than one entry. Serialized as ref_multiple. |
| AllowJsonRte | bool? | No | null | Marks the field as a JSON Rich Text Editor. Serialized as allow_json_rte. |
| EmbedEntry | bool? | No | null | Allows embedded entries in a rich text editor. Serialized as embed_entry. |
FileFieldMetadata properties. FileFieldMetadata derives from FieldMetadata and is the type of ImageField.FieldMetadata. It adds the property below.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| AllowOnlyImage | bool | No | false | Limits the file field to images. Serialized as image. |
Class-Level Notes
Values the SDK always sends.
- The SDK always sends allow_rich_text, multiline, markdown, and ref_multiple with false, and version with 0, when you leave them unset. Set each one to the value your field needs.
- The SDK leaves out every nullable property that is null, including allow_json_rte and embed_entry.
Default values.
- DefaultValue accepts any value, and the SDK serializes it by its runtime type. After a fetch, it holds a JsonElement.
- The descriptions in the table above come from the comments in the SDK source. The Create a content type request of the Content Management API reference links the full JSON schema of each field type.
Method Index
FieldMetadata has no methods. Set its properties and assign the object to the FieldMetadata property of a field.
Class-Level Snippet
The snippet below creates a content type with a rich text field that has instructions for editors, and a summary field with a placeholder.
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 = "Body",
Uid = "body",
DataType = "text",
FieldMetadata = new FieldMetadata
{
AllowRichText = true,
RichTextType = "custom",
Options = new List<string> { "h3", "blockquote", "sup" },
Version = 3,
Instruction = "Write the full article."
}
},
new TextboxField
{
DisplayName = "Summary",
Uid = "summary",
DataType = "text",
FieldMetadata = new FieldMetadata { Multiline = true, Placeholder = "Two sentences that describe the post", DefaultValue = "" }
}
}
};
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}");
}