Hi Folks,
Any idea how to make alternate text a mandatory field when inserting images? I've had a look through the forums and found a reference to an old version of fckeditor but I'm wondering if this is possible in ckeditor 3.x?
Any thoughts? Perhaps this should be integrated as a standard feature into the core code?
Any idea how to make alternate text a mandatory field when inserting images? I've had a look through the forums and found a reference to an old version of fckeditor but I'm wondering if this is possible in ckeditor 3.x?
Any thoughts? Perhaps this should be integrated as a standard feature into the core code?
Re: Mandatory alternate text for Images
ckeditor\plugins\image\dialogs\image.js
And search for "txtAlt"
under that you can see all the functions defined namely setup, commit etc
After the commit function, add this text:
,validate : CKEDITOR.dialog.validate.notEmpty( 'Alt text is missing' )
note the comma in the beginning... this is required to say that you are adding a new function called validate after commit function. In fact you can add this at any line but it has to be separated from other functions with a comma. And the message "Alt text is missing" is just a sample I used, you can choose your own message and even put them in lang/en.js file and refer to it similar to how it has been referred for the URL missing message.
If you want to see a properly indented code in image.js, open the same file available in _source\plugins\image\dialogs\image.js and you can understand better how it's done and do it similarly in the other folder.
If it's confusing, let me know.
Re: Mandatory alternate text for Images
Hi a_shyam41,

That works a charm! Thank you very much!
Re: Mandatory alternate text for Images
that's a big help! Hope CKEditor has this feature soon.
Instead of modifying the
Instead of modifying the contents of those files, it's much better if you create an additional plugin to modify the dialog definition on-the-fly, that way you can upgrade more easily as you don't have to redo your changes (besides that messing with compressed code is always ugly)
Instead of modifying the
I believe lot of users are not developer and dont know how to create an additional plugin.
The asterisk for required fields
I noticed that when you do this, there is no astrisk to indicate that this field is required. Apparently, this is a known CKEditor issue.
As a workaround, you can also add a class to the field and use CSS to add a red asterisk, like so:
// on your alt element, in image.js
className: 'ck-alt-required',
// CSS rules:
.ck-alt-required label:after {
content: '*';
color: red;
}