XbyX Combining Visibility Conditions in a Generic reusable way

2025/03/25 9:31 AM

I'm in the process of designing a content type which has some fields that will be shown/hidden based on the value of other fields in the form using visibility conditions.

One of the fields will need to be shown based on the value of multiple fields but it seems you can only configure visibility based on a single dependent field (out of the box):

1.00


In the example above, my field is only shown when ShowButton1 is true but I'd like it to depend on the value of an additional field.

Example of what I'd like to achieve, from K13:

The old visibility editor allowed us to build up complex expressions on the fly.

I've seen that it's possible to create a custom visibility condition which allows for multiple dependent fields: https://docs.kentico.com/developers-and-admins/customization/extend-the-administration-interface/ui-form-components/ui-form-component-visibility-conditions#visibility-conditions-with-field-dependencies

And this does work:

However I believe we would need to create a new visibility condition every time we encounter a need to depend on multiple field values which is a bit cumbersome.

Is there a way to achieve the same result but letting the CMS editor determine which fields the control depends on instead of overriding and hard coding the DependsOnFields property?

Environment

  • Xperience by Kentico version: [30.2.2]
  • .NET version: [8]

Answers

2025/03/25 1:54 PM

I ran into this as well. There's also another 'issue' is that while doing multiple field visibility works, it only works if those fields themselves don't have a visibility condition. I would submit to the Roadmap (https://roadmap.kentico.com/) that you want this functionality back, i do too :(

2025/03/28 8:37 AM
Answer

I managed to solve this on my own but it's not pretty. There doesn't appear to be a way of doing this out of the box so I've submitted it to the roadmap as a suggestion.

To achieve this, I added a field to the custom visibility condition which accepts some JSON configuration describing the dependent fields and expected values:

1.00

The visibility condition parses the JSON and queries the IFormFieldValueProvider to determine whether to hide/show a field based on the dependent field values and conditions.

Here's a gist with the complete code: https://gist.github.com/DGibbsCrafted/a772819998fffbd330551947096526b7

To answer this question, you have to login first.