Search code examples
javascriptruby-on-railsckeditorreadonly

CKEditor ReadOnly with Enabled Toolbar Buttons


I am working in Rails project, setting a CKEditor instance to true for readOnly mode. That works well.

My next step is trying to enable in the toolbar a custom plugin button while keeping the textarea in readOnly mode.

I have found an example here: https://dev.ckeditor.com/ticket/8959 describing that in the definition of the plugin I can define if readOnly is available for setting.

As a result of this recommendation, in my code I have done this:

editor.ui.add('normal_values', CKEDITOR.UI_MENUBUTTON, {
  label: 'Reference Ranges',
        modes: {wysiwyg: 1},
        readOnly: 0,
        icon: '<%= asset_path("icons/book-open.png") %>',
        onMenu: function () {
                var active = {};
                 for (var p in items)
                  active[p] = CKEDITOR.TRISTATE_OFF;

                 return active;
                }
            });

The property comes through when I debug in the browser Toolbar Object in Javascript Chrome Debugger

but it still does not bring up the plugin.

I am not sure what else to try so any suggestions or help would be extremely helpful.

Thank you in advance


Solution

  • This property readOnly:true shoud be set in "command" definition not in "button"

    If command is a custom dialog

    editor.addCommand( 'LockUI', new CKEDITOR.dialogCommand( 'lockUIDialog' ));
    

    Just append property readOnly

    var cmd=new CKEDITOR.dialogCommand( 'lockUIDialog' );
        cmd.readOnly=true;
        editor.addCommand( 'LockUI', cmd );