Key text field characters stripped on render

We often use key text fields for simple strings in our content. Today we came across an issue where we store HTML for an email template (the Rich Text field doesn't provide enough of the formatting we use so it cannot be used in this instance).

We have some placeholders in that email template for various user fields and custom per-user links e.g

<a href="{signup_link}">Click here</a>

Although this is saved correctly first time, once published and you go back to the page the ="{signup_link}" is stripped out from the editor, and if you then save again that content is lost entirely. We tried various workarounds for this (including <a {signup_link}> and various others) and all got stripped out.

This feels like a bug as it saves correctly first time (and retrieves fine from the API)?

James

Hello @frstie, thanks for reaching out.

Is this happening inside the documents of your Prismic repository or your application?
Could you show me a visual example? A screenshot or screen recording.

Thanks

Hi @Pau

Here's a simple example - Title here is a Key Text field. Enter the following:

After clicking save and publish:

Notice that the ="{link}" has disappeared.

At this point the document is saved correctly to the repository as per the API browser:

image

However if I then make a change to that field the change is lost (unless I enter it all again including the stripped out characters)

Hope that makes sense,

James

1 Like

I recommend that you switch the Key Text for a Rich Text field. It allows much more formatting options. And for this specific case, you can paste this piece of code inside a preformatted tag. It'll be returned in the following form in the API:

{
  "type": "preformatted",
  "text": "<a href=\"{signup_link}\">Click here</a>",
  "spans": [ ]
}

I'm not sure if accepting HTML tags is the intended behaviour of the Key Text Field, but I'll inform the team. Thank you for the additional details!

Hi @Pau

Thanks for getting back to me. We explicitly don't want any formatting for this field - it is essentially the HTML for an email template with some placeholders embedded.

In most cases a Key Text field works as you'd expect for this, other than this odd behaviour in the editing screen in Prismic.

In the end we had to use a Rich Text field for this, not allow any tags apart from paragraphs, and reconstruct the plain text string at the website end from the result, which is not ideal.

If there are good reasons to restrict what can be entered into a Key Text field perhaps another, simpler Plain Text field could be added that didn't have this restriction?

James

You are right, because this is more likely to be an error in the operation of the Field than its normal behaviour. Sorry for the inconvenience this causes.

I have already informed the team about this case. Now we will follow up on the issue tracker.

1 Like

This thread is being monitored as an open ticket in the internal Prismic issue tracker. The Prismic support team will update this post as we get more information from our dev team. If you have a similar use-case, you can ‘Flag’ this topic to reopen and add it here.