Search code examples
sitecoresitecore8

Is it possible to add custom validation to validate sitecore rendering datasource?


I need to validate the referenced datasource item fields based on the rendering it is used in. Since the datasource items are used in multiple components I need a rendering based validation. Is it possible to achieve this in sitecore?


Solution

  • Indeed in case if you want to validate fields and do it exactly on rendering you have to use Sitecore Rendering Parameters. How to use that you can find here. The main idea:

    1. your data source template should be based on /system/layout/rendering parameters/Standard Rendering Parameters one.
    2. your rendering should contain a reference to the appropriate template within Parameters Template field (Editor Options section).
    3. you have to setup necessary validations to fields of template (mentioned in 1st point). This post will be helpful.

    After that when you click on Edit component properties on your rendering: enter image description here

    You will see the additional section in Control Properties window (Data on the screen below). It comes from template mentioned in 1st point: enter image description here

    As an example I setup Required validation rule to Text field to show that it works.