Mark Handy
Mark Handy

Reputation: 1256

Kentico 9 macro for form field visibility

I have a custom page type, and the editor will have the option to enter the following

The field names are as follows

So, if an editor ads a SlideImage, SlideVideo and YouTubeVideoID should not be usable. Same for SlideVideo and YouTubeVideoID.

Within the Visibility Condition fields, i'm going to assume a macro is needed for this. My logic is:

This field visible if Field A or B have data.

Upvotes: 0

Views: 745

Answers (3)

Kristian Bortnik
Kristian Bortnik

Reputation: 838

A possible approach can be to add an additional field, which determines the field that should be used.

Create a text field (let's say, SlideType) and use a radio button form control with your options:

image;Image
video;Video
youtube;YouTube

Tick the "Has depending fields" checkbox for this field, and tick the "Depends on another field" checkbox for the SlideImage, SlideVideo and YouTubeVideoID fields.

Your visibility conditions would then be simplified, instead of checking the values of multiple fields.

For example, the visibility condition for the SlideVideo field would be:

SlideType == "video"

This has a few benefits:

  1. Easy to add new fields and configure the visibility conditions
  2. Easy to check what needs to be rendered in the front-end - in your repeaters and other webparts, you can simply have conditional statements on the SlideType field to determine which field to use
  3. Intuitive for the end user - the interface makes it clear which field is being used

Upvotes: 1

Chetan Sharma
Chetan Sharma

Reputation: 1442

Let's say the column name on which this value of your depending field is "FirstName", so you can write in the dependent field -> Visibility Condition as

FirstName.value != "" or

FirstName.value

You can twist the conditions for as many conditions as possible and can club more than one condition too.

I am also sharing links with you having a lot of examples from Kentico support

Dependency fields in Kentico

Using dependency fields in forms

Cheers, Chetan

Upvotes: 0

Martin Makarsky
Martin Makarsky

Reputation: 2650

Add this to Visibility condition in Page type field edit:

Fields.SlideImage.Value == String.Empty

Do not forget to set proper Has depending fields and Depends on another field properties depending on your needs. You can learn more about these properties here.

Upvotes: 0

Related Questions