CKEditor Plugin: text fields not editable
Asked Answered
S

7

22

I am creating a CKEditor plugin, using version 4.2.1. I am trying to follow the tutorial on a Simple Plugin. However, the text inputs in my dialog window are not editable / clickable in the dialog, even when I just copy in the entire abbr plugin from the tutorial with no changes.

I can still click the dialog tabs, OK / Cancel buttons, and drag the dialog around. I have added in other elements (like selects) to the dialog in my custom version, and I can interact with those.

When I check the text input elements in Chrome's Dev Tools, I can add text via the Console / jQuery and it appears. I get no failures in the Console.

$('#cke_229_textInput').val('help');

Will add text to the text input and display it on the screen. But I can't interact with the element via mouse / keyboard / browser. Is there something obvious in the CKEditor configuration that I am missing? Sorry if this is a really stupid question--first time working with CKEditor. I have also searched the CKEditor forums and Google, without finding any related issues.

This happens in both Chrome 30 and FF 24.

My call to create the editor:

var me = document.getElementById('resource_editor_raw');
editor = CKEDITOR.replace(me, {
    fullPage: true,
    removePlugins: 'newpage,forms,templates',
    extraPlugins: 'abbr',
    allowedContent: true
});

Thanks for any tips or hints!


Update #1

Thinking this might be related, I have also tried setting the z-index of the text element to very high, using Chrome's Dev Tools. No luck, it is still not editable / highlightable...


Update #2

This seems to be this conflict with jQuery UI. The suggested fix doesn't work for me yet, but will poke around...leaving this up for anyone who might stumble across it.


Final Update

So Brian's tip helped me. Both the Bootbox modal backdrop (what I am using to generate the original dialog) and the CKEditor dialog backdrop have tabindex=-1, so they conflict somehow. Manually turning off the Bootbox backdrop (i.e. setting tabindex='') works with Chrome dev tools, so I think I can hack something together with jQuery or whatnot. Amazing stuff...thanks for the help!! Not sure why I got this working in a jsFiddle...if I recall correctly, I might not have had a backdrop on those dialogs.

Also, for reference, a tabindex of -1 makes things untabbable, which makes sense for a backdrop.

Shipwreck answered 24/10, 2013 at 15:49 Comment(1)
In Bootstrap 5, all I needed to do is add data-bs-focus="false" to the html. But this was to get the edit link window working again, not a custom plugin.Gainsay
A
33

The modal html attribute tabindex='-1' is what seems to be causing the issues for me.

The tabindex='-1' is actually in the bootstrap documentation and is needed for some reason that I am unaware of.

Auburta answered 31/1, 2014 at 17:44 Comment(2)
Hi Brian, thanks for the response, I also put that in there because of the Bootstrap docs. I'll maybe fiddle with this a little more tomorrow, with your insight in mind. I did get the suggested fix working in a jsfiddle, so I know it should work...Shipwreck
Hm, so this is also my problem. I am using the bootbox library to create the first modal, and its backdrop has a tabindex of -1. But the ckeditor backdrop also has a tabindex of -1, and they appear to conflict. Removing the tabindex on the bootbox backdrop fixes the problem. I can probably hack my way around this now--thanks!!Shipwreck
M
7

Use the 100% working script..

<script type="text/javascript">
    // Include this file AFTER both jQuery and bootstrap are loaded.
    $.fn.modal.Constructor.prototype.enforceFocus = function() {
      modal_this = this
      $(document).on('focusin.modal', function (e) {
        if (modal_this.$element[0] !== e.target && !modal_this.$element.has(e.target).length 
        && !$(e.target.parentNode).hasClass('cke_dialog_ui_input_select') 
        && !$(e.target.parentNode).hasClass('cke_dialog_ui_input_textarea')
        && !$(e.target.parentNode).hasClass('cke_dialog_ui_input_text')) {
          modal_this.$element.focus()
        }
      })
    };
</script>

Note: Include this file after both jQuery and bootstrap are loaded.

Martinamartindale answered 16/6, 2017 at 11:45 Comment(1)
Worked like charm! :) Thanks a lot.Stahl
C
5

Not sure if anyone else is having this issue now. I was ripping my hair out trying to create a hack. It was a pretty simple solution after a while of digging and search the web. This fix helped me. Just place it on the same page where you want to place your editor - when loading from jQuery. The issue is conflicting tabindex, so I simply removed that attribute from the modal.

<script>
$(function(){ 
       // APPLY THE EDITOR TO THE TEXTAREA
       $(".wysiwyg").ckeditor();

       // FIXING THE MODAL/CKEDITOR ISSUE
       $(".modal").removeAttr("tabindex");
});
</script>
Chancery answered 30/1, 2019 at 20:37 Comment(1)
your solution didn't work for me this way. I had to modify $('.modal').attr('tabindex', ''); then it workedSexagesima
G
3

OMG I have been googling this for hours and finally fond some code that works!!

Stick this in your dialog page that will have a ckeditor in it:

orig_allowInteraction = $.ui.dialog.prototype._allowInteraction;
$.ui.dialog.prototype._allowInteraction = function(event) {
   if ($(event.target).closest('.cke_dialog').length) {
      return true;
   }
   return orig_allowInteraction.apply(this, arguments);
};

I found the fix here: https://forum.jquery.com/topic/can-t-edit-fields-of-ckeditor-in-jquery-ui-modal-dialog

Game answered 22/1, 2015 at 10:27 Comment(0)
T
1

I am using Semantic UI and fix this problem by create an instance of CKEDITOR after create Modal.

    $('#modal-send').modal('attach events', '.btn-close-modal').modal('show');
    var ckeOptions = {
        entities: false,
        htmlEncodeOutput: false,
        htmlDecodeOutput: true
    }

    CKEDITOR.replace('message', ckeOptions);
    CKEDITOR.config.extraPlugins = 'justify';
Trollope answered 17/12, 2019 at 3:41 Comment(0)
M
0

I also faced this issue when I updated the CKEditor into 4.14 I found the fix in here - http://jsfiddle.net/kamelkev/HU8Qt/3/ In this case,

$.widget("ui.dialog", $.ui.dialog, {
        _allowInteraction: function (event) {
            return !!$(event.target).closest(".cke").length || this._super(event);
        }
    });

It will return false, so the textbox gets disabled/ unfocused (losing focus) As a solution, we need to return true or need to modify the class .cke in the return statement into .cke_dialog

 return !!$(event.target).closest(".cke").length || this._super(event);
Melchior answered 4/6, 2020 at 5:43 Comment(0)
I
-2

I tried to upload images to server from CK Editor[without CKFinder] and on positive side i am able to do. whenever we are trying to create some dialog, they are creating one div on the fly which will hold your dialog box. Better you check the CSS property for your text box using chrome and change it. Hope this will help you.

Infusionism answered 6/2, 2014 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.