Unable to add content to Textarea editor on Redactor 2. "Uncaught TypeError: Cannot read property 'code' of undefined"

302 views Asked by At

I have Redactor II (version 1.2.5) which I used to edit content on a database. When the page is loaded I load the content that needs to be edited, and I use the following code to add the content in to the Redactor editor:

$('#eg_description').redactor('code.set', 'My text goes here');

However, when I load the page I get this error:

Uncaught TypeError: Cannot read property 'code' of undefined

I've also tried this:

$('#eg_description').redactor('this.code.set', 'My text goes here');

Which gives the following similar error:

Uncaught TypeError: Cannot read property 'this' of undefined

Not entirely sure why it isn't working, so any help would be appreciated!

1

There are 1 answers

0
Andrei Hryhoryeu On

Please make sure you first enable Redactor on the same element, i.e. you call

$('#eg_description').redactor(); //you can provide options object here