Do you see any JavaScript errors in your browsers console?
I slightly changed your code, and tested this. It worked.
public class ImageBlockValidator : IValidate<ImageBlock>
{
public IEnumerable<ValidationError> Validate(ImageBlock imageBlock)
{
if (imageBlock.Image != null && string.IsNullOrEmpty(imageBlock.ImageAlt))
{
yield return new ValidationError
{
ErrorMessage = "Oh no! Gimme some alt!",
PropertyName = nameof(imageBlock.ImageAlt),
RelatedProperties = new[] { nameof(imageBlock.Image) },
Severity = ValidationErrorSeverity.Error,
ValidationType = ValidationErrorType.StorageValidation
};
}
}
}
Episerver.Cms.Core 11.15.0
Thanks for your help but it still doesn't work.
There is a javascript error when clicking the save button:
Object { message: "Unable to load /EPiServer/cms/Stores/contentdata/ status: 409", stack: "_317@http://localhost:90/EPiServer/Shell/11.23.6/ClientResources/dojo/dojo.js:15:78148\n_4f2@http://localhost:90/EPiServer/Shell/11.23.6/ClientResources/dojo/dojo.js:15:133806\n_4fe@http://localhost:90/EPiServer/Shell/11.23.6/ClientResources/dojo/dojo.js:15:134085\n", response: {…}, status: 409, responseText: "The page was not displayed because there was a conflict.", xhr: XMLHttpRequest }
dojo.js:15:123181
If you create your block from assets pane, it should work.
Same issue as described here: https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2017/12/409-conflict-creating-block/
We have a block with properties Image and ImageAlt. To get the ImageAlt to be required if the user add an Image we created a custom validation class for the block.
But when a user add an Image and click "Spara" no error message is shown i the UI, the "Spara" button gets inactive and nothing happens. The block isn´t saved.
But if the user saves the block before adding an Image and then goes back to edit the block and adds an Image the validation error message is shown.