Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea editor Redactor. Insert value with jQuery

Have field textarea id="tr" using HTML editor Redactor last version trying to set value of the field exactly haw it is described in API Doc :

$('#tr').redactor('insertText', 'text'); 

or

$('#tr').redactor('insertHtml', 'text');

What am I doing wrong ?

like image 303
abiku Avatar asked Oct 25 '13 12:10

abiku


1 Answers

If you are using an old version of redactor, you can try the set API, which I think is a lower-level version of insertText/insertHtml.

So in your example, it should be:

$('#tr').redactor('set', 'Your text goes here');

Update (2015-04-21): In redactor v2, the name of the set method was changed:

$('#tr').redactor('code.set', 'Your text goes here');

Another Update (2020-04-20): In their latest version, Imperavi changed their syntax and provided two ways to achieve this solution:

const editor = $R('#tr');
editor.source.setCode('Your text goes here');
    

or

$R('#tr', 'source.setCode', 'Your text goes here');
like image 107
MForMarlon Avatar answered Nov 15 '22 22:11

MForMarlon