Question

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 ?

Was it helpful?

Solution

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');

OTHER TIPS

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

$('#redactor_subcontentid').destroyEditor();
// set it to new 
$('#redactor_subcontentid').redactor().setCode("Your Text");

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top