Sign up (with export icon)

Restricted editing

Contribute to this guideShow the table of contents

The restricted editing feature introduces two modes: the standard editing mode and the restricted editing mode. Users working in the restricted editing mode cannot change the content, except for parts marked as editable.

Unlock this feature with selected CKEditor Plans

Try all premium features – no credit card needed.

Sign up for a free trial Select a Plan

Demo

Copy link

The demo below lets you emulate both the standard editing mode and the restricted editing mode.

Start by creating a template of the document in the standard editing mode. Select a section of the text and use the enable editing toolbar button Enable editing to turn a selected area into an editable region or remove an existing one.

Then switch to the restricted editing mode to see how the editable and non-editable regions behave.

Tip

Use Tab to navigate from one editable region to another (and Shift+Tab to move back) in the restricted mode.

Mode:

Dear Customer Name,

thank you for contacting us. Your case has been logged as Case ID and assigned to Technician Name. We will try to resolve your issue within the next Time hours.

Should you need any further assistance, do not hesitate to contact our Customer Support Hotline at Hotline Number.

Please follow this checklist before the technician arrives:

Yours sincerely,
Name
Customer Support Team

Additional feature information

Copy link

The restricted editing feature enables two editing modes:

  • Standard editing mode – In this mode the user can edit the content and choose regions that should be editable in the restricted editing mode.
  • Restricted editing mode – When you initialize the editor in this mode, the user can edit the content only within the regions chosen by the user in the standard editing mode. There changes allowed withing these fields can be configured.

There are two types of editable fields: inline and block.

  • Inline editable fields only allow content editing with features enabled in the restricted mode. This kind of field can only hold inline content. They support only inline-type changes. Users can type, delete content, and format the text. However, no block-type editions are available. This means no splitting paragraphs (striking the Enter key) is allowed. Tables or block images cannot be added in this field, either.
  • Block editable fields enable all content editing features loaded in the editor. Content inside the block can be anything, including lists, tables, images etc. (providing these features are loaded into the editor).

You can observe it in the demo while switching between the inline and the block editable field – the number of active toolbar items will change.

Both block and inline fields can be inserted via the toolbar dropdown Enable editing. The availability of one or both types of fields from the toolbar can be configured.

You can imagine a workflow where a certain group of users is responsible for creating templates of documents. At the same time, a second group of users can only fill the gaps (for example, fill in the missing data, like names, dates, product names, etc.).

By using this feature, the users of your application will be able to create template documents. In a certain way, you can use this feature to generate forms with rich-text capabilities. This kind of practical application is shown in the How to create ready-to-print documents with CKEditor 5 pagination feature blog post.

Note

See also the read-only feature that lets you turn the entire WYSIWYG editor into read-only mode. You can also read the dedicated blog post about write-restricted editor modes.

Installation

Copy link

After installing the editor, add the feature to your plugin list and toolbar configuration.

Running the standard editing mode

Copy link

To initialize the editor in the standard editing mode, add the StandardEditingMode plugin and add the 'restrictedEditingException:dropdown' button to the toolbar:

import { ClassicEditor, StandardEditingMode } from 'ckeditor5';

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		licenseKey: '<YOUR_LICENSE_KEY>', // Or 'GPL'.
		plugins: [ StandardEditingMode, /* ... */ ],
		toolbar: [ 'restrictedEditingException:dropdown', /* ... */ ]
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
Copy code
Note

Please note there are available toolbar items for inline, block, and both types of editable fields. Read more in the Configuring the tollbar section.

Running the restricted editing mode

Copy link

To initialize the editor in the restricted editing mode, add the RestrictedEditingMode plugin and add the 'restrictedEditing' button to the toolbar:

import { ClassicEditor, RestrictedEditingMode } from 'ckeditor5';

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		licenseKey: '<YOUR_LICENSE_KEY>', // Or 'GPL'.
		plugins: [ RestrictedEditingMode, /* ... */ ],
		toolbar: [ 'restrictedEditing', /* ... */ ]
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
Copy code

Configuration

Copy link

You can configure which features should be available in the inline editing field. For instance, the following configuration allows the users to type, delete but also to bold text.

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        // ... Other confituration options ...
        restrictedEditing: {
            allowedCommands: [ 'bold' ]
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );
Copy code

Note: Typing and deleting text is always possible in restricted editing regions. For more information, check out the config.restrictedEditing documentation.

Enabling commands in the restricted editing mode

Copy link

The restricted editing mode allows modifying the editor content only in designated regions. Outside these regions, most of the editor commands are turned off by default. If you wish to enable some commands outside the restricted editing regions, you can use the RestrictedEditingModeEditing.enableCommand() method. You must execute this method in the afterInit() callback of an editor plugin.

import { ClassicEditor, Plugin } from 'ckeditor5';

class MyPlugin extends Plugin {
	afterInit() {
		this.editor.plugins.get( 'RestrictedEditingModeEditing' ).enableCommand( 'myCommand' );
	}
}
Copy code

Configuring the toolbar

Copy link

When configuring the toolbar item for inserting restricted editing fields in standard mode, you can choose to provide your users with access to inline, block or both types of fields. To add these to the toolbar, you should use the following toolbar item calls, respectively: restrictedEditingException:dropdown (both types of fields available), restrictedEditingException:inline, and restrictedEditingException:block.

Example toolbar configuration may look like the one below:

toolbar: [
    'restrictedEditingException:dropdown', '|',
    'heading', '|', 'bold', 'italic', 'link', '|',
    'bulletedList', 'numberedList', 'todolist', 'outdent', 'indent', '|',
    'blockQuote', 'insertImage', 'insertTable', '|',
    'undo', 'redo'
]
Copy code

To configure the feature toolbar button for restricted mode, use the restrictedEditing call, instead. The Navigate editable regions button Navigate editable regions allows for moving between previous/next editable fields.

Example toolbar configuration may look like the one below. Please note that whatever toolbar items maybe enable, the two different types of editable fields will not support all of them.. From the example below, inline editable fields will only support bold, italic, link, and undo, while images, tables, and list will only be available for block type fields.

toolbar: {
    items: [
        'restrictedEditing', '|', 
        'heading', '|', 'bold', 'italic', `link`, '|',
        'bulletedList', 'numberedList', 'todoList', 'outdent', 'indent', '|',
        'insertImage', 'insertTable', '|',
        'undo', 'redo'
    ]
}
Copy code

Legacy toolbar button

Copy link

The new toolbar items were introduced with version 47.2.0. To retain full backwards compatibility, we have provided an alias toolbar item: restrictedEditingException. It is the old toolbar button call and it defaults to inline restricted editing field button. There is no need to change your configuration if you only want to use inline fields type.

Copy link

CKEditor 5 has more features that help you control user permissions:

  • Read-only – Turn the entire content of the editor read-only.
  • Track changes – Mark user changes in the content and show them as suggestions in the sidebar for acceptance or rejection.
  • Comments – Users can add comments to any part of the content instead of editing it directly.
Note

Read this CKEditor blog post on how to couple restricted editing with other features to create editable document templates.

Common API

Copy link

The StandardEditingMode plugin registers:

  • The 'restrictedEditingException:dropdown' button that lets you mark regions as editable.
  • The 'restrictedEditingException:inline' button that lets you mark inline regions as editable.
  • The 'restrictedEditingException:block' button that lets you mark block regions as editable.
  • The 'restrictedEditingException' button that lets you mark inline regions as editable (legacy alias).
  • The 'restrictedEditingException' command that allows marking inline regions as editable.
  • The 'restrictedEditingExceptionBlock' command that allows marking block regions as editable.

The RestrictedEditingMode plugin registers:

  • The 'restrictedEditing' dropdown that lets you navigate between editable regions.
  • The 'goToPreviousRestrictedEditingException' and 'goToNextRestrictedEditingException' commands that allow navigating between editable regions.
Note

We recommend using the official CKEditor 5 inspector for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.

Real-time collaboration

Copy link

When using real-time collaboration, all the connected users should always be in the same mode. You cannot have a different list of plugins enabled among users of a single collaborative session.

Contribute

Copy link

The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-restricted-editing.