Restrict media validation to only media library

66 views Asked by At

I have applied field validation (AltRequired)to media library images .But it's also giving validation error to images used in any item in content editor where alt text is empty in used image . Is there any way to remove validation from item under content and restrict it up to media library image only

I have applied to altRequired field validation to media library images

1

There are 1 answers

0
mikaelnet On

I like to see the built-in validators in Sitecore as examples. I find them rarely usable as-is in real world scenarios. I think they lack many configuration options and when introducing multiple language layers etc., they tend to be a bit buggy.

I'd suggest you make your own set of validators that meet your requirements. Thereby you can fine tune what severity levels you want, give user friendly validation messages and have suitable logic for what should happen when item versions are missing etc.

When it comes to image ALT texts, they can be either sourced from the image item itself or from the image field where they're used, where the later value takes precedence. Therefore you'll need two different kind of validators for the two. You can assign a Required validator in the media item ALT-field itself. Consider if you want it to be a hard (Error-level) och soft (Warning-level) requirement. For the image fields, it would probably make more sense to fail validation if neither the appointed image nor the image field itself has an alt text. Also consider if you need this validation on all image fields (field type validation) or if you need different rules on different image fields (field validator).

Last, but not least, validators are assigned in multiple fields causing them to run at different scenarios. Make sure long-running and/or CPU heavy validators aren't assigned to the Quick action bar, as it will run for every item shown in the content tree as it unfolds. At the same time, it should be user-friendly. Validators that only runs and fails in the Workflow rule set may cause confusion among editors for example. Therefore it's sometimes needed to build multiple variants of the same validator, where the frequently executed ones does a "fast exit" and perhaps gives a vague error message while the other may perform a more users-friendly, in-depth validation when validation is performed by request by the author (through the validation button or via workflow transition for example)