wysihtml5 - setting a value won't work, because 'sandbox iframe isn't loaded yet'

Fabi picture Fabi · Aug 20, 2013 · Viewed 9.4k times · Source

I'm just working on a little webservice. Therefore I am using an AJAX call and append my data to a table on my website. Here I can read and update already existing entries or write new entries. Everything works fine.

I want to have the possibility to update already existing with the wysihtml5 editor. I already integrated this editor on my website and I can use it on new entries. That works, too.

But now there's the problem with existing data. When it comes to the form to update data, I want the existing data being displayed as the value. Everything works fine on all inputs, just the wysihtml5 don't work.

I already know that there's an iframe and that's why I can't set the value of the textarea. I searched for a solution and found the following code (last line):

var editor = new wysihtml5.Editor("textareaid", { // id of textarea element
        toolbar: "wysihtml5-toolbar", // id of toolbar element
        parserRules: wysihtml5ParserRules, // defined in parser rules set
});

editor.setValue('Here's the content', true);

Usually this should work, but no content appears and the console just tells me:

Error: wysihtml5.Sandbox: Sandbox iframe isn't loaded yet

I tried it with a timeout-function but nothing works. Searching on the internet it also seems that there is noone else with that problem. I hope you can help me out, would be great!

Is there a way to set the value?

Answer

Tushar T. picture Tushar T. · Jun 21, 2015

This code work for me

$("#product_details").data("wysihtml5").editor.getValue();// to get the value
$("#product_details").data("wysihtml5").editor.setValue('new content')// to set the value