{"pageProps":{"error":null,"preview":false,"file":{"fileRelativePath":"content/docs/plugins/fields.md","data":{"frontmatter":{"title":"Field Plugins","prev":"/docs/plugins/forms","next":"/docs/plugins/content-creators"},"excerpt":" Fields are added to forms via the fields array and create the editing interface of a form. Field Config All field plugins share a common config: Default Field Plugins These are the default field…","markdownBody":"\nFields are added to forms via the `fields` array and create the editing interface of a form.\n\n## Field Config\n\nAll field plugins share a common config:\n\n```typescript\ninterface FieldConfig {\n name: string\n component: string | ReactComponent\n label?: string\n parse?(value: any, name: string, field: Field): any\n format?(value: any, name: string, field: Field): any\n validate?(\n value: any,\n allValues: any,\n meta: any,\n field: Field\n ): string | object | undefined\n}\n```\n\n| key | description |\n| ----------- | ---------------------------------------------------------------------------------------------- |\n| `name` | Equivalent of an input's `name` attribute. |\n| `component` | Either a string denoting a field already registered with the CMS, or a custom field component. |\n| `label` | _Optional:_ A label to render above the field input. |\n| `parse` | _Optional:_ Prepare the data for usage in the field component. |\n| `format` | _Optional:_ Prepare the data for saving. |\n| `validate` | _Optional:_ Return undefined when valid. Return a string or an object when there are errors. |\n\n## Default Field Plugins\n\nThese are the default field plugins available through the CMS:\n\n- [Text](/docs/plugins/fields/text)\n- [Textarea](/docs/plugins/fields/textarea)\n- [Number](/docs/plugins/fields/number)\n- [Image](/docs/plugins/fields/image)\n- [Color](/docs/plugins/fields/color) _May be external soon_\n- [Toggle](/docs/plugins/fields/toggle)\n- [Select](/docs/plugins/fields/select)\n- [Tags](/docs/plugins/fields/tags)\n- [List](/docs/plugins/fields/list)\n- [Group](/docs/plugins/fields/group)\n- [Group List](/docs/plugins/fields/group-list)\n- [Blocks](/docs/plugins/fields/blocks)\n\n## External Field Plugins\n\nThese are plugins that must be installed through separate packages:\n\n- [Date & Time](/docs/plugins/fields/date)\n- [Markdown](/docs/plugins/fields/markdown)\n- [HTML](/docs/plugins/fields/html)\n\n## Field Definition\n\nYou can add fields to a form through the `fields` array in the [form configuration](/docs/plugins/forms#form-configuration). The Field definition at minimum needs a `name` and `component`. This is an example of a simple [`text`](/docs/plugins/fields/text) field definition.\n\n**Example form configuration**\n\n```js\nconst formOptions = {\n id: 'lynel-hoofs',\n label: 'Edit This Page',\n fields: [\n {\n name: 'tagline',\n component: 'text',\n },\n ],\n}\n```\n\n> Refer to individual field plugin docs for additional examples.\n\n### _name_\n\nThe `name` property connects the field with the source data by providing the path to that content from the root of the source data.\n\nFor example, say we had a JSON object:\n\n```json\n{\n \"headline\": \"Banana Pancakes\"\n}\n```\n\nOur field definition to edit `headline` would be:\n\n```js\n{\n fields: [\n {\n name: 'headline',\n component: 'text',\n },\n ],\n}\n```\n\nIf the data structure looked a little different:\n\n```json\n{\n \"hero\": {\n \"headline\": \"Banana Pancakes\"\n }\n}\n```\n\nThe `name` property should be updated to reflect the different path:\n\n```js\n{\n fields: [\n {\n name: 'hero.headline',\n component: 'text',\n },\n ],\n}\n```\n\n### _component_\n\nThe `component` field property can either be the name of a field plugin (a string), or a React Component.\n\nAll of the previous examples show the `component` being set with a string:\n\n```js\n{\n fields: [\n {\n name: 'background_color',\n component: 'color',\n },\n ],\n}\n```\n\n`'color'` is referring to the `name` of the Color [Field Plugin](/docs/plugins/fields/custom-fields#2-creating-field-plugins) that is hooked up to the CMS by default.\n\nYou can also define components inline to render in place of a default field:\n\n**Example**\n\n```js\nconst formOptions = {\n label: 'My Page',\n fields: [\n {\n label: \"Athlete's Name\",\n name: 'name',\n component: 'text',\n },\n // The custom inline field\n {\n name: '_',\n component: () =>