[WIP] Conditional fields

We already have several features that can hopefully satisfied with a single feature request, for example:

  • As a user I want to show or hide fields based on another field.
  • As a user I want to give translators only access to one language
  • As a user I want to have conditional validation rules (mostly required).

The idea is to implement conditional fields:

A conditional field is a rule that is applied to one or more fields and invokes an action when a condition is true. This condition is expressed as a JavaScript expression to make the implementation easy and powerful.

Actions are:

  • Hide: Hide the field in the UI when opening a single content item.
  • Disable: Disable the field in the UI.
  • Require: Make the field required for the UI.
  • Do not require: Make the field optional in the UI.

This feature is focused on the UI for now. The backend part can be implemented via scripts anyway.

Conditions are expressed as javascript with access to the following values:

  • data (the current data of the form)
  • itemData (the current data of the item when the field is nested)
  • user (the current user)
  • field (the field object)

Q & A

Why is it only a UI feature

There are several reasons:

  1. To make it easier to implement this.
  2. To improve performance. It takes relatively long to evaluate dozens of scripts per content item. Conditional fields also make sense for queries, but then performance suffers. It is faster to implement it with a single schema script.
  3. To have less code to maintain.

Is scripting to hard to work with?

Yes, a good editor to define your conditions would improve the usability but it is a lot of effort and not that powerful.

Will there ever be a condition editor.

Very likely not, the migration will also be horrible.

What is the MVP (minimum viable product)?

  1. Two actions (hide and disable)
  2. Only total fields (not per language as shown above)
  3. Only evaluate conditions in the UI.

UPDATE

Usage in Array

Definition

1 Like