This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed
Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff 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: ' +
Original file line number Diff line number Diff 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 ( / ^ e d i t o r - c r e a t e - i n i t i a l - d a t a : T h e c o n f i g \. i n i t i a l D a t a o p t i o n c a n n o t b e u s e d t o g e t h e r w i t h i n i t i a l d a t a p a s s e d i n E d i t o r \. c r e a t e \( \) \. / ) ;
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 ( / ^ e d i t o r - w r o n g - e l e m e n t : T h i s t y p e o f e d i t o r c a n n o t b e i n i t i a l i z e d i n s i d e < t e x t a r e a > e l e m e n t \. / ) ;
156+ }
157+ )
158+ . then ( done )
159+ . catch ( done ) ;
135160 } ) ;
136161
137162 function test ( getElementOrData ) {
You can’t perform that action at this time.
0 commit comments