Views: 1661
Number of votes: 4
Average rating:

page validations

There are instances when Editors should to be informed in form of warning and information rather to stop them and display error messages. For self note IValidate interface can be used for this purpose. e.g

public class StandardPageValidator : IValidate<StandardPage>
        public IEnumerable<ValidationError> Validate(StandardPage instance)
            if (instance.Name.Length < 10)
                return new List<ValidationError>() {
                    new ValidationError() {
                        ErrorMessage ="Name is very short",
                        PropertyName = "Name",
                        Severity =ValidationErrorSeverity.Info,
                        ValidationType =ValidationErrorType.AttributeMatched

            return Enumerable.Empty< ValidationError>();

Image information.jpg


Aug 18, 2016

( 8/19/2016 5:35:51 PM)

Good post.  One additional thing I would mention here is that you can compare multiple fields as part of your validation logic, which gives the interface a bit more flexibility than other methods.

K Khan
( By K Khan, 8/19/2016 7:07:07 PM)

Good point Janaka, Thanks for sharing!

David Strøm
( By David Strøm, 8/24/2016 11:15:57 AM)

I have begun using this kind of validation for required properties instead of the builltin functionality which shows the editor a very anonymous form with the required fields. In my opinion the editor can easily loose track of context when they see this form.

Instead I use the IValidate to handle required fields and other validations. Exactly as you describe it. Then the editor has the context of the whole content type.

Good of you to put some spotlight on the IValidate functionality.

K Khan
( By K Khan, 8/24/2016 11:24:34 AM)

Thanks for sharing your approach, That makes sense!

( 8/24/2016 9:59:15 PM)

We use this all the time and as David said it's perfect for validate several fields if you whish.  You can actually manipulate the data in the properties. Unfortunately the changes made in a validation isn'r reflected in the UI so the editor can see. I played around with it and you can read a blog post about it here.

K Khan
( By K Khan, 8/25/2016 9:52:48 AM)

Here we go! Thanks Per :), I remeber this now, You post is really a good reference point on this topic.

Please login to comment.