Page level validation for a block property value in CMS edit view.

Vote:
 

In CMS edit, Suppose if a page is having multiple blocks of the same type, a specific block property value should be unique across all the blocks within the same page. Is there a way we can validate if a block's property is unique across a page? for ex: a buttons ID, to ensure that the ID is not duplicated in the same page. This will help the editors from giving duplicate ID's while rendering the page.

#225343
Jul 13, 2020 14:50
Vote:
 

Hi Anish,

Why you want this id value from content editor?

I think you can generate random id in your code while rendering the blocks.

#225346
Jul 13, 2020 16:53
Vote:
 

This is required to track the GTM click ID for analytcs and other purposes like A/B testing.

#225347
Jul 13, 2020 17:04
Vote:
 

You can use the IValidate<T> (example IValidate<ContentPage>) and inside that access your content area and blocks added into that. See below link for summarised code to add validation for the blocks added on a page.

https://www.jondjones.com/learn-episerver-cms/episerver-developers-tutorials/episerver-content-areas/how-to-create-a-custom-content-area-validator-in-episerver/

Let me know if you need further help.

Thanks

#225367
Jul 14, 2020 7:17
Vote:
 

Thanks for replying. I am using a button block which is used in multiple other blocks. I need to ensure that the ID field in button block is unique within a page. For that I need to get all the button blocks within the current page from all its children and then perform the validation. This may sound strange but there is a requirement to provide the editors the option to give button ID's. Also, the page can have multiple content areas like heading content, main content and side content, so this becomes bit complex.

#225374
Jul 14, 2020 10:52
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.