Contentful logo

Contentful Community

Show or hide fields in Content creation

In the WebApp, is it possible to have some logic in Content Types to show or hide fields depending on the value of other fields when we create Content?

For example, let’s say our Content Type have two fields:

  • Nationality (mandatory): a dropdown menu with two options: [“US citizen”, “Other”].
  • Country (optional): a dropdown menu with several countries
    In this case, if nationality is “US citizen” we don’t need to fill the country field so it would be great to hide this field.
1 Like

Hi @jesus.talaveragomez,

We don’t have a formal logic mechanism to be implemented throughout fields, but it is something that you can achieve using our UI extension SDK:

1 Like

Hi @gabriel, would you be able to elaborate a little bit more on this. I’m trying to do this from a UI Extension and I’m able to access the controls of the content type using the SDK property (sdk.editor.editorInterface.controls) but I don’t know how to manipulate the visibility of the fields using the SDK and when trying to do it via JS, the browser blocks the script because of the cross-origin frame policy.