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.

4 Likes

Just saw this on the Marketplace Conditional Fields by Prototyp | Contentful

since contentfu/ui-extensions-sdk is already discouraged

After looking into this for some while now… it doesn’t seem to be possible to change the visibility of a field using an external app.
As @fluxa mentioned, an external application is not allowed to access the parent document from within the iframe, you will get a DOMException.

So the only way seems to be to host the application with contentful, or write an extension.