Custom validation for «Manage Expiration and Archiving».

Vote:
 

I am well aware of how custom validation of regular properties can be done, but how can I validate the input in the window for «Manage Expiration and Archiving»?

I would like to make «Archive to» required for some page types, if «Expire date» has a value.

I have tried adding this:

public class ExpirePageValidator : IValidate
{
    IEnumerable IValidate.Validate(ExpirePage page)
    {
        if (page.StopPublish != null && page.ArchiveLink == PageReference.EmptyReference)
        {
            return new[]
            {
                new ValidationError
                {
                    ErrorMessage = "Varför gör ni på detta viset?",
                    PropertyName = page.GetPropertyName(page => page.ArchiveLink),
                    Severity = ValidationErrorSeverity.Warning,
                    ValidationType = ValidationErrorType.AttributeMatched
                }
            };
        }
          return Enumerable.Empty();
    }
}


The code runs when the expiration date are saved, but the validation message are not shown until other changes are published. Most of the time there are no other changes, so the validation message will never be shown.

How can I solve this?

#177327
Edited, Apr 07, 2017 15:24
Vote:
 

Have you seen this recent blog post

https://www.codeart.dk/blog/2019/11/episerver-forms-adding-custom-validators-to-existing-elements/

I am not 100% sure about if will work for you, but this can give you heads-up. Best of luck :)

#210440
Nov 23, 2019 4:18
Vote:
 

the closest I got was using IContentEvents. it of course look like page is expired (updated UI + yellow bar), but editor will also see validation error (if you cancel ContentSavingEvent)..

couldn't find better way

#210479
Nov 25, 2019 12:53
Vote:
 

i would love to have events on expiry, its strange they dont exist now, expiry goes around the publishing process, would be great if Epi could pick this up as a feature enhacement to allow hooks into expiry for validation etc

#210508
Nov 26, 2019 12:55
Vote:
 

Benjamin,
Please submit your enhancement request to https://world.episerver.com/forum/developer-forum/Feature-requests/.

#210527
Nov 26, 2019 17:46
Vote:
 

Validation for Manage Expiration and archiving can be done by below methods:

  1. Create a custom class let say CustomEventInitialization implementing interface IInitializable Module.
  2. Resolve dependency for interface IContentEvents.
  3. Register your publishing event in Initialize method.
  4. Then in your publishing event method check for : page.StopPublish date
  5. On basis of your business conditions , you can use vallidations now on the basis of event properties.
  6. event.CancelReason = "validation message", event.CancelAction =true/false.
#251987
Mar 29, 2021 14:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.