I've asked my question on the Github page of CKEDITOR here, I've been asked to ask it here: https://github.com/ckeditor/ckeditor4/issues/3555
I'm working with CKEDITOR to make content editable. The editor is opened in a bootstrap modal when I click on a button, which is maybe why it doesn't work. The problem here is that I can't have the focus on fields required to insert content in the editor.
Two screenshots to understand the problem: https://i.sstatic.net/hrzhY.jpg - When I can't write anything in the inputs, no focus
https://i.sstatic.net/Xmy0b.jpg - When I try to validate, because nothing has been written
This is my CKEditor config:
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see https://ckeditor.com/legal/ckeditor-oss-license
*/
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
config.uiColor = '#AADC6E';
config.extraPlugins = 'ckawesome';
config.fontawesomePath = 'C:/wamp64/www/landing/fontawesome-free-5.10.2-web/css/fontawesome.css';
config.extraPlugins = 'fontawesome';
config.allowedContent = true;
CKEDITOR.dtd.$removeEmpty['i'] = false;
CKEDITOR.dtd.$removeEmpty['span'] = false;
config.protectedSource.push(/<i[^>]*><\/i>/g);
config.disallowedContent = '<br />';
config.toolbar = 'editor1';
config.toolbar_editor1 = [
{ name: 'document', items: [ 'Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates' ] },
{ name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
{ name: 'editing', items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
{ name: 'forms', items: [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
'/',
{ name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat' ] },
{ name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language' ] },
{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
{ name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe' ] },
'/',
{ name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{ name: 'tools', items: [ 'Maximize', 'ShowBlocks' ] },
{ name: 'about', items: [ 'About' ] },
{ name: 'insert', items: [ 'FontAwesome' ] }
];
};
(the full one, + Font Awesome plugin for the moment)
And this is the parts of my code that make it work:
HTML:
<!-- Modal pop-up for CKEditor -->
<div class="modal" id="wysiwyg-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add custom content</h5>
</div>
<div class="modal-body">
<!-- Hey! -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" id="close-editor" data-dismiss="modal">Save</button>
</div>
</div>
</div>
</div>
JS:
// At the beginning of my document ready
// To append the editor
$(".modal-body").append('<div><p name="editor1" id="editor1"></p></div>');
// To avoid conflicts
for(name in CKEDITOR.instances)
{
CKEDITOR.instances[name].destroy(true);
}
// At the beginning too, to avoid a breakline each time I open my editor again
CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;
CKEDITOR.config.shiftEnterMode = CKEDITOR.ENTER_BR;
// When I click on a button to open the editor
$('#wysiwyg-modal').modal('show')
CKEDITOR.replace('editor1', {
toolbar: 'editor1',
//uiColor: '#FFDC6E',
});
Thanks for helping out.
EDIT: Totally randomly, I hit the Escape key just when I clicked on one of the plugins that require to enter text, like the image one. It made the modal close but the plugin form still opened itself and I was able to type in the fields. If I fill in the fields and try to press 'OK', I get an error 'b is undefined'.
Here is a screen: https://i.sstatic.net/ip8SS.jpg
I fixed the problem.
Bootstrap modals have a property tabindex="-1"
, which made the CKEDITOR plugins inputs to loose their focus. Just delete it!