cs-icon.svg

Add a Field Visibility Rule

Field Visibility Rules in Contentstack allow authorized users to dynamically show or hide fields within an entry based on predefined conditions, improving content management and user experience. By setting up rules, users can control when fields appear, streamline data entry, and reduce clutter.

This guide outlines the steps to create and configure these rules, including defining conditions, setting actions, and managing multiple rules effectively.

When creating or editing a content type or a global field, you can define field visibility rules based on specific conditions in the respective builder page.

Note: Only users with permission to create or edit content types can configure the field visibility rules.

Set Up Field Visibility Rules for a Content Type

To set up field visibility rules, log in to your Contentstack account and perform the following steps:

  1. Go to your stack and click the "Content Models" icon.
  2. Click the title of a content type to open it. Alternatively, click the vertical ellipses in the Actions column next to the content type and select Edit.
  3. Click Field Visibility Rules at the top of the page.

    Field Visibility Rules UI
  4. In the resulting modal, click Create New Rule.
  5. Under RULE 1, configure the rule as follows:

    1. Select whether the rule should apply when All or Any of the specified conditions are met:

      • All: The action triggers when all specified conditions are met.
      • Any: The action triggers when at least one specified condition is met.
    2. Specify the conditions:

      • Select a Field from the dropdown. This is the operand to be evaluated.
      • Choose a Condition. This is an operator that defines the comparison.

        Additional Resource: Refer to the Operand Fields and Supported Operators document for more details.

      • Enter an expected Value that triggers the condition.

      Example Condition: If "Date" is Before "12-31-2024".

      • Operand Field: Date
      • Condition (operator): Before
      • Expected Value: 12-31-2024

      Tip: You can add more conditions to a rule by clicking + Add Condition or remove them by clicking the delete icon.

    3. In the Perform the following actions section, define the actions triggered when the condition is met.

      • Select Show or Hide action type from the dropdown.
      • Choose a target Field to be shown or hidden based on the condition.

      For example, if "Date" is Before "12-31-2024", Show the Archive Notification field and Hide the Body field.

      Tip: You can add more actions to a condition by clicking + Add Action or remove an action by clicking the delete icon.

    Note: Refer to the Limitations of Field Visibility Rules document to know more about the validations on the operand field and target field.

    Setting up actions in Field Visibility Rules

    Tip: You can add multiple rules to a content type by clicking + Add Another Rule or remove a rule by clicking the Delete Rule option from the vertical ellipsis.

  6. Click Save to apply the rule(s).
  7. Click Save or Save and Close to apply changes to the content type.

Set Up Field Visibility Rules for a Global Field

You can apple Field Visibility Rules to Global Fields, allowing you to control the visibility of fields inside a reusable component.

To set up field visibility rules for a global field, log in to your Contentstack account and perform the following steps:

  1. Go to your stack and click the Content Models icon.
  2. Select Global Fields from the left navigation panel.
  3. Click the title of a global field to open it.
  4. Click Field Visibility Rules at the top of the page.
  5. Create and configure rules using the same steps as for content types.

    Note: Fields marked as multiple cannot be used in rules within a Global field.

  6. Click Save to apply the rule(s).
  7. Click Save or Save and Close to apply changes to the global field.Set_Up_Field_Visibility_Rules_for_a_Global_Field.png

How Rules Work in Content Types

When a Global Field with visibility rules is referenced in a content type:

  • The rules are inherited and shown in the Rules from Global Fields (Read-only) section in the Content Type builder.
  • Inherited rules cannot be edited or deleted from the Content Type; you must edit them in the Global Field itself.
  • Any rules created directly in the Content Type are independent and remain editable there.

Field Visibility Rules give you granular control over which fields appear to content managers, simplifying the entry view and improving usability. Using these rules effectively can improve data accuracy, streamline workflows, and make complex content models easier to work with, especially when managing reusable components through Global fields.

Was this article helpful?
^