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.
Why you want this id value from content editor?
I think you can generate random id in your code while rendering the blocks.
This is required to track the GTM click ID for analytcs and other purposes like A/B testing.
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.
Let me know if you need further help.
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.
I know I am late to the party for this one, but one thing you could do is append a value to the id in the razor view to make it unique. Simple thing might be to pass an int to the partial view, or use a DateTime.Tick.
I have used this successfully on a client site.