Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor getEditor() Error, How to fix it?

<textarea cols="50" id="txt" contenteditable="true" name="editor1" runat="server" rows="10"></textarea>
<script type="text/javascript" src="css-js/ckeditor.js"></script>
<script type="text/javascript">
  CKEDITOR.replace('txt', {                    
  });       
</script>

I get this err on js :

TypeError: Cannot call method 'getEditor' of undefined

like image 437
Bip Avatar asked Sep 30 '13 08:09

Bip


People also ask

How do I get CKEditor in HTML?

var objEditor = CKEDITOR. instances["sectionTextArea"]; var q = objEditor. getData(); This will get me the text entered in CKEditor, without any markup.

How do I get CKEditor value?

you can add the following code : the ckeditor field data will be stored in $('#ELEMENT_ID'). val() via each click. I've used the method and it works very well. ckeditor field data will be saved realtime and will be ready for sending.


4 Answers

First of all, contenteditable="true" tag is totally invalid and obsolete in your case. Such attribute is relevant for inline instances only and, as <textarea> is not (content)editable, you don't need it.

Anyway, (even if buggy) your code works for me like a charm (fiddle). As a word of explanation, the error you see is produced when there's no element of an id passed to CKEDITOR.replace(), i.e:

<textarea id="foo"></textarea>
<script type="text/javascript">
     CKEDITOR.replace( 'bar' ); // <textarea> is #foo, error will be thrown
</script>

Make sure your DOM is valid and <textarea> exist when CKEDITOR.replace is called (working async?).

like image 180
oleq Avatar answered Oct 18 '22 21:10

oleq


Use

CKEDITOR.appendTo( 'txt' ); for DOM elements

CKEDITOR.replace( 'textarea' ); for textarea

Ok dude try this also

the functions appendTo and replace are all located in themedui.js file

try adding it separately,here is the link

http://docs.ckeditor.com/source/ckeditor.html#CKEDITOR

like image 39
jayadevkv Avatar answered Oct 18 '22 22:10

jayadevkv


if you just want to get rid of that, use

try{CKEDITOR.replace('body')}catch{}

it will cause CKEDITOR to open where you want it to

like image 25
Sanjay Avatar answered Oct 18 '22 22:10

Sanjay


I had a similar problem and sorted it by doing the following;

<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
    if($("textarea").length > 0){
        CKEDITOR.replace( 'ckeditor' );
    }
</script>
like image 35
mjcoder Avatar answered Oct 18 '22 21:10

mjcoder