London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

IValidate interface for multiple pagetypes

Vote:
 

Hi All,

I am new to EPiServer. I am using IValidate interface for validating the default property of episerver page i.e CategoryList. I would like to restrict the count of category selection for example say only one category should be selected. I did this for a single pagetype, But i am getting the following exception , while adding additional page types,"Ambiguous match found". It may be simple one i may not know. I have attached my code below.

public class BasePageValidator : IValidate,IValidate
    {        

        IEnumerable IValidate.Validate(SamplePage page)
        {           
            if (page != null && page.Category.Count > 1)
            {
                return new[] 
                 { 
                    new ValidationError() 
                    { 
                       ErrorMessage = "Field IntroText cannot be empty!", 
                       PropertyName = page.GetPropertyName(pg => pg.Category),
                       Severity = ValidationErrorSeverity.Warning, 
                       ValidationType = ValidationErrorType.AttributeMatched
                    } 
                 };
            }
            return Enumerable.Empty();;
        }

        IEnumerable IValidate.Validate(Products page)
        {            
           return Enumerable.Empty();
        }
        
    }

It is not working after adding "IValidate", getting an exception.

I need to set this restriction for some pagetypes more than one. Suggest me on how to achive this one.

Thanks in advance.

#143243
Jan 18, 2016 14:27
Vote:
 

Hi

If I remember correctly IValidate supports being registered against interfaces. So you could add an interface to SamplePage and Products, something like IMustHaveCategory, and then register your validator as IValidate<IMustHaveCategory>. Would that work?

Regards

Per Gunsarfs

#143246
Jan 18, 2016 14:57
Vote:
 

Is it possible to highlight a field with yellow colour if it fails validation with severity warning. Currently, only for severity Error it highlights the field with red colour, ex: Required field validation.

#210408
Nov 21, 2019 17:43
- Feb 21, 2020 14:17
It would be possible to add this functionality using Dojo. But there is no built in support for this.
* 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.