Custom validation on EPi 7

Vote:
 

Hi, guys,

Have you tried out EPi 7's custom validation?

The error is returned when the validation condition is broken. However, when I fix the thing that is causing the validation error, auto save always returns: "Offline, can't save" and hitting Publish, gives me the validation error.

This is the code:

    public class RowBlockValidator : IValidate<RowBlock>
    {
        IEnumerable<ValidationError> IValidate<RowBlock>.Validate(RowBlock instance)
        {
            if (instance.OneToFourBlocks != null)
            {
                if (instance.OneToFourBlocks.Count > 4)
                {
                    var validationError = new ValidationError
                    {
                        ErrorMessage = "Content area can contain up to four blocks",
                        PropertyName = "OneToFourBlocks",
                        RelatedProperties = new string[] { "OneToFourBlocks" },
                        Severity = ValidationErrorSeverity.Error,
                        ValidationType = ValidationErrorType.AttributeMatched
                    };

                    return new[] {validationError};
                }
            }


            return null;
        }
    }

    

#65064
Jan 18, 2013 15:04
Vote:
 

Hi,

I've built a number of custom IValidate classes and have never experienced such issues. I have however never set anything else than ErrorMessage and PropertyName on my ValidationErrors. I usually also return Enumerable.Empty<ValidationError>(). Neither of those differences should matter though.

#65080
Jan 18, 2013 23:36
Vote:
 

Hi Marija

I had same problem as you had, I can't recreate it, but it did happen few times to me. 

#65094
Jan 20, 2013 23:51
Vote:
 

Now, I have changed it to return Enumerable.Empty<ValidationError>(); and tried out a couple of times with this and return null.

Every time return null gives me the problem described and return Enumerable.Empty<ValidationError>(); gives me the correct behavior.

#65102
Jan 21, 2013 11:06
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.