2

I have a Block Type which has these two properties.

[CultureSpecific]
[Display(
Name = "Display PDF Button", GroupName = TabNames.PDFCustomisation, Order = 0)]
public virtual bool DisplayPdfButton { get; set; }

[CultureSpecific]
[Required]
[Display(
Name = "Download Pdf Text", GroupName = TabNames.PDFCustomisation, Order = 1)]
public virtual string DownloadPdfText { get; set; }

I only want DownloadPdfText to be required if the user sets DisplayPdfButton to True. - Is this possible to do in Episerver?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Ayo Adesina
  • 2,231
  • 3
  • 37
  • 71

2 Answers2

2

Another way is to implement an event handler for custom validation, for example the SavingContent or PublishingContent events.

That way, you can look at the type of content being saved and/or published, and decide whether to validate or not.

The event handler argument has properties that can be set to stop saving/publishing, and also specify a reason (look at the CancelAction and CancelReason properties).

Here is an example of such an event handler.

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
1

One way of doing this is to implement your own validation attribute. You can make it validate to false if DisplayPdfButton is checked and DownloadPdfText is empty. Read about how to do it here: https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Content/Properties/Property-types/Writing-custom-attributes/

andreasnico
  • 1,478
  • 14
  • 23
  • 1
    For my scenario I went with this approach - However these are some clearer URLs to explain how to do it: https://blog.wsol.com/improving-episervers-content-editing-experience-through-validation and... http://henrikm.com/custom-episerver-property-validation/ – Ayo Adesina Apr 13 '18 at 11:12