Joel Peltonen
Joel Peltonen

Reputation: 13432

Controlling save button enabled/disabled state programmatically

How would I enable/disable the save button of CKEditor using external JS? I don't want to remove it completely, just change the appearance between gray and colored icon so that it's more user friendly.

My save button is generated like so:

CKEDITOR.plugins.registered['save'] =
{
    init : function( editor )
    {
        var command = editor.addCommand( 'save', {
            modes : { wysiwyg:1, source:1 },
            exec : function( editor ) {
                if(My.Own.CheckDirty())
                    My.Own.Save();
                else
                    alert("No changes.");
            }
        });
        editor.ui.addButton( 'Save',{label : '',command : 'save'});
    }
}

Upvotes: 6

Views: 8389

Answers (1)

oleq
oleq

Reputation: 15895

Here you go:

For 3.6.x:

CKEDITOR.instances.yourEditorInstance.getCommand( 'save' ).disable();
CKEDITOR.instances.yourEditorInstance.getCommand( 'save' ).enable();

For 4.x:

CKEDITOR.instances.yourEditorInstance.commands.save.disable();
CKEDITOR.instances.yourEditorInstance.commands.save.enable();

Upvotes: 15

Related Questions