9

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 ?

Pascalz
  • 2,348
  • 1
  • 24
  • 25
abiku
  • 2,236
  • 3
  • 25
  • 30

3 Answers3

26

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');
MForMarlon
  • 865
  • 9
  • 24
0

This code work perfectly for destroy and then update to new.

$('#redactor_subcontentid').destroyEditor();
// set it to new 
$('#redactor_subcontentid').redactor().setCode("Your Text");
4b0
  • 21,981
  • 30
  • 95
  • 142
itzmevant
  • 31
  • 4
0

I am using version 8 from 2013, which has the following code:

$( '.redactor' ).setCode( 'text' );

I found this in from archive.org: https://web.archive.org/web/20121228195235/http://imperavi.com/redactor/docs/api

If none of the above work for you, check which version you have and find the relevant documentation by changing the date on archive.org.

Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48