Sometimes you might need to change how your text content is being delivered and you may be worried about losing this content in the process. Don't worry we've thought ahead. We've made this process secure and quick so you won't lose anything, though it takes a little concentration and some editing of the JSON.

To change the text field type you can not simply remove a field in build mode and add another with the same name, this will result in a loss of data. You must make a small change in the JSON. So first go to your custom type and select the 'JSON editor' tab.

 

From Rich Text to Key Text

For the process of changing 'Rich Text' to 'Key Text' you will need to change the type from "StructuredText" to just "Text". Then in the config, you remove the entire "multi" or "single" section, which holds the options for the 'Rich Text' field. After you've made this, click to save your Custom Type.

Once you've saved your Custom Type, you will see the change immediately in the Prismic UI. But to see the change made in the API for your existing documents of this type, check out the Updating existing documents section below.

 

From Key Text to Rich Text

To perform this process for changing 'Key Text' to 'Rich Text' simply perform this operation in reverse. In the JSON editor for your type, find the field in question and change "Text" to "StructuredText". Then add the formatting options that you want available for the 'Rich Text' field.

Here is an example:

"text-field" : {
  "type" : "StructuredText",
  "config" : {
    "multi" : "paragraph, preformatted, heading1, heading2, heading3, heading4, heading5, heading6, strong, em, hyperlink, image, embed, list-item, o-list-item, o-list-item",
    "label" : "This is now a Rich Text field"
  }
},


Once you've saved your Custom Type with this change, you will see the change immediately in the Prismic UI. But to see the change made in the API for your existing documents of this type, check out the Updating existing documents section below.

 

Updating existing documents

When switching between Rich Text and Key Text, the changes will become visible immediately in the Prismic UI. But the API response for any existing document will not automatically be updated with this change.

In order to see the switch for a document in the API, you need to make a small change to your text field in your document (for example, add a space or make small edit that you can quickly change), then save and publish the document. 

After you've done this, you will see the updated field type in your API response for this document.

Note:
You will need to perform the final step for every document where you have a text field. This is not so bad if you only have a few documents, but we are aware that if you have many document this can become very tedious.

So for those of you dealing with a large collection of documents we recommend using our 'Import/Export' feature as the final step in the process after editing your custom type. This will allow you export, make bulk changes, then import again. Hopefully that should save some time.

The 'Import/Export' feature is available starting on the Medium plan and you can read more about it here.


Hopefully this helps you understand how to change your text fields from one type to another!

Did this answer your question?