Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit af4daea

Browse files
authored
Merge pull request #32 from ckeditor/t/ckeditor5/1591
Feature: `DecoupledEditor.create()` will throw an error, when textarea element is used.
2 parents 5d0c0d7 + e49f6cf commit af4daea

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/decouplededitor.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ export default class DecoupledEditor extends Editor {
214214
*/
215215
static create( sourceElementOrData, config = {} ) {
216216
return new Promise( resolve => {
217+
const isHTMLElement = isElement( sourceElementOrData );
218+
219+
if ( isHTMLElement && sourceElementOrData.tagName === 'TEXTAREA' ) {
220+
// Documented in core/editor/editor.js
221+
throw new CKEditorError( 'editor-wrong-element: This type of editor cannot be initialized inside <textarea> element.' );
222+
}
223+
217224
const editor = new this( sourceElementOrData, config );
218225

219226
resolve(
@@ -222,7 +229,7 @@ export default class DecoupledEditor extends Editor {
222229
editor.ui.init();
223230
} )
224231
.then( () => {
225-
if ( !isElement( sourceElementOrData ) && config.initialData ) {
232+
if ( !isHTMLElement && config.initialData ) {
226233
// Documented in core/editor/editorconfig.jdoc.
227234
throw new CKEditorError(
228235
'editor-create-initial-data: ' +

tests/decouplededitor.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,34 @@ describe( 'DecoupledEditor', () => {
129129
DecoupledEditor.create( '<p>Hello world!</p>', {
130130
initialData: '<p>I am evil!</p>',
131131
plugins: [ Paragraph ]
132-
} ).catch( () => {
133-
done();
134-
} );
132+
} )
133+
.then(
134+
() => {
135+
expect.fail( 'Decoupled editor should throw an error when both initial data are passed' );
136+
},
137+
err => {
138+
expect( err ).to.be.an( 'error' ).with.property( 'message' ).and
139+
// eslint-disable-next-line max-len
140+
.match( /^editor-create-initial-data: The config\.initialData option cannot be used together with initial data passed in Editor\.create\(\)\./ );
141+
}
142+
)
143+
.then( done )
144+
.catch( done );
145+
} );
146+
147+
it( 'throws error if it is initialized in textarea', done => {
148+
DecoupledEditor.create( document.createElement( 'textarea' ) )
149+
.then(
150+
() => {
151+
expect.fail( 'Decoupled editor should throw an error when is initialized in textarea.' );
152+
},
153+
err => {
154+
expect( err ).to.be.an( 'error' ).with.property( 'message' ).and
155+
.match( /^editor-wrong-element: This type of editor cannot be initialized inside <textarea> element\./ );
156+
}
157+
)
158+
.then( done )
159+
.catch( done );
135160
} );
136161

137162
function test( getElementOrData ) {

0 commit comments

Comments
 (0)