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.

Continue reading “Template dependent field validator WITHOUT Sitecore rules engine”

Template dependent field validator with Sitecore Rules Engine

I got a requirement that I need to create more data templates with the same fields but the fields should have different validations based on the template. So I decided to create a base template and inherit the other templates from this. Now, how can I assign different validators for the fields based on the template?

Continue reading “Template dependent field validator with Sitecore Rules Engine”