Template dependent field validator WITHOUT Sitecore rules engine

A year ago I have posted about how to create template dependent field validator with rules engine. But it requires too many modifications, so I have decided to write this post about how to do the similar functionality without rules engine.

So at first I have implemented a base class which should be used by all validators which want to be dependent on a template or a base template. This class does the following steps:

  1. Checks the template ID and base template ID of the current item
  2. If it is true then the main part is called, this is the following line:
return evaluate();

This is the injected specific validation method which is passed as a parameter.

So we have already the base class. This is doing the most of the job, what is left is to inject our specific validator. Here you can see an example with the RequiredFieldValidator.

The last thing we have to do is to create the proper Validation Rule item in Sitecore. The TemplateIdToFind is the ID of the template or the base template which defines, on which items should the validator run. To do this, navigate to

/sitecore/system/Settings/Validation Rules/Field Rules

and create your Validation Rule item from

/sitecore/templates/System/Validation/Validation Rule

Capture

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s