Try implementing the validation through an class implementing the IValidate interface for the content type instead. This may work for you https://world.episerver.com/documentation/developer-guides/CMS/Content/Validation/
Hi Scott,
Thank you for help on this.
Using IValidate interface this max limit warning will not be removed on switching tabs within cms but IValidate interface will be specific to that particular page if we are using it and can't be generalized(Correct me if I am wrong in understanding this one).
And can we pass the limit from model property?
In the following code snippet max limit 2 is hard coded, can this be passed from model property?
public class ContentPageValidator : IValidate<MainSheetNavigationBlock>
{
public IEnumerable<ValidationError> Validate(MainSheetNavigationBlock page)
{
if (page.NavigationItems != null && page.NavigationItems.Count >= 2)
{
return new ValidationError[]
{
new ValidationError()
{
ErrorMessage = string.Format(
CultureInfo.CurrentCulture,
"{0} has {1} item(s) and cannot contain more than {2}.",
page.GetPropertyName(p => p.NavigationItems),
page.NavigationItems.Count,
2),
PropertyName = page.GetPropertyName(p => p.NavigationItems),
Severity = ValidationErrorSeverity.Error,
ValidationType = ValidationErrorType.StorageValidation
}
};
}
return Enumerable.Empty<ValidationError>();
}
}
We have used content area validation to have limit on items within content area, but when we switch tab and modify that tab items will remove validation on content area and allow us to add more item in content area and publish the item. Try adding this to hide add new block link from content area https://world.episerver.com/blogs/tuan-do/dates/2017/8/limiting-items-in-a-contentarea/ but its not working and giving error in cms.
Can you please suggest how to deal with this scenario.