Search code examples
contentful

How can I set different label and value for dropdown fields in Contentful


I'm new to Contentful and trying to create a simple dropdown field where I define a different value and label for each of the options. But I can't seem to figure out how to do it.

I've created a dropdown by creating a Short text Field, setting Appearance to Dropdown and checking off Accept only specified values under Validation:

Field validation settings

But it only allows me to set the label part, which will automatically be used as value as well. Since a lot of my values translate to enums, it's weird for a normal user to have something like TYPE_CAMPAIGN instead of "Campaign" in a dropdown menu.

As an example of what I'm looking for, in Advanced Custom Fields (WordPress), I can do it by typing TYPE_CAMPAIGN : Campaign, which results in <option value="TYPE_CAMPAIGN">Campaign</option>

Can a similar thing be done in Contentful?


Solution

  • Contentful DevRel here. 👋

    For the short text field we don't support this functionality. There are two ways to solve this use case.

    Create a content type for it

    You could create a separated content type and solve the use case that way. Instead of using short text you can then reference entries of this separated content type. You can store your enum there and it also has the advantage that you can extend it with additional fields in the future.

    Extend the Contentful interface using the App Framework (or UI extension)

    Another option is to leverage the App Framework. The Framework allows you to replace fields (, entries or even complete pages) with your logic. This way you could render a select with labels and values as it fits.