Field Rules
Learn About Field Rules in Squidex
Last updated
Learn About Field Rules in Squidex
Last updated
This documentation is based on the FoodCrunch use case. Please open the link below alongside this page to understand the examples.
A Field Rule is a method of implementing automated actions on schema fields when a certain condition is met. It is made up of three components as follows:
Action: This component states what should be done when the condition(s) is/are met. It has the following options:
Disable
Hide
Require
Field: This relates to when the schema field is selected dependent upon which action should be taken.
Condition: Written in Javascript, this action is triggered when the condition is met.
For our FoodCrunch user case let's consider the following example to understand Field Rules. For all startups that are not in Pre-Seed
stage, the funding value must be mentioned. It is therefore a required field.
For our use case, the rule is that anytime the value of the Stage field is anything other than Pre-Seed
, then the Funding is a required field, otherwise it's optional.
Let's see how to implement this:
Ensure that the Validation (2) of the Stage (1) field is set to Required (3) in the settings. This is necessary to make sure that a value is always selected.
To create a Field Rule, go to the Schema (1) (i.e. in our case startups
), select the More (2) tab, click + (3) under Field Rules and enter the selections for Action, Field and Condition (4). Click Save (5) when done.
In our example the following values have been set:
Action = Require
Field = funding
Condition (in Javascript) = data.stage.iv != 'Pre-Seed'
This can now be validated by trying to add content. Go to Content and try adding content. Immediately you will find that the stage and funding fields have a red flag.
If you set stage as Pre-Seed
, the red flag denoting that the funding value is required will disappear, which means its optional.
If you set stage as any other value, the red flag remains meaning that a value has to be entered in funding.