Skip to content

Instantly share code, notes, and snippets.

@wilr
Last active February 23, 2019 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilr/95d328821940724046c8ec92c3c6111d to your computer and use it in GitHub Desktop.
Save wilr/95d328821940724046c8ec92c3c6111d to your computer and use it in GitHub Desktop.
SilverStripe 4, Require the user to enter alt text for the image
import Injector from 'lib/Injector';
Injector.transform(
'require-alt-text',
(updater) => {
updater.form.addValidation(
'AssetAdmin.*',
(values, Validation) => {
if (typeof values.AltText === 'undefined') {
return;
}
const alt = (!values.AltText || values.AltText.length < 1) ? 'Alt text is required' : null
if (alt) {
Validation.addError('AltText', alt);
}
}
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment