Try our conversational search powered by Generative AI!

K Khan
Aug 18, 2016
  2438
(4 votes)

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

References:

http://world.episerver.com/documentation/Class-library/?documentId=episerverframework/7.5/e53f458f-f4a1-2904-620d-cad9167f3387

http://world.episerver.com/documentation/Class-library/?documentId=episerverframework/7.5/2a269a53-76ff-8c86-5984-5512fbe9f9b9

Aug 18, 2016

Comments

Aug 19, 2016 05:35 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
K Khan Aug 19, 2016 07:07 PM

Good point Janaka, Thanks for sharing!

David Strøm
David Strøm Aug 24, 2016 11:15 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
K Khan Aug 24, 2016 11:24 AM

Thanks for sharing your approach, That makes sense!

Aug 24, 2016 09:59 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
K Khan Aug 25, 2016 09:52 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.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024