bootstrap-wysihtml5
bootstrap-wysihtml5 copied to clipboard
How to populate editor once initialised via jquery
Am having trouble populating the editor after it has been initialised.
The documentation says you can access the instance and write to it via something like.
$('#textarea-id').wysihtml5().data("wysihtml5").editor.setValue('test');
However this only populates the hidden <input type="textarea"> as opposed to the editor itself.
If I go to the demo (http://xing.github.com/wysihtml5/examples/advanced.html) and execute ...
editor.setValue("foobar");
... then the editor gets updated and shows "foobar". Correctly.
I can use the editor.setValue as above to populate the editor, but I have multiple editors on a singe plage, so ideally i'd use the first scenario where i can target the instance I want to write to.
Any advice/suggestions?
I've also had the same issue, I hacked the iframe to show the correct value(note that the selector is very specific to my use case):
$('div[for="' + this.textEditorView.id + '"].editor-container').find('iframe').contents().find('.wysihtml5-editor').html(revertTo.get('text'));
But if you can get to the iframe, you can set the html value. Got the idea from this post here: https://github.com/xing/wysihtml5/issues/118
Haha, that was my post too! :)
Thanks, I am using the way suggested in the linked post, however I know there is a native setValue function within the editor object for this, which would be a lot quicker and resilient to any changes in my dom.
It's just how to access individual editor objects when there are multiple ones on a page, and they've been initialised via bootstrap-wysihtml5
Thanks though!
Yeah, I have the same issue, lots of individual editors. And I access them by their "id" and select each one, as much as I tried to use the documented way, I couldn't get the iframe to change the text. All of the other elements around the iframe were no problem.
Thanks for the clever hack! :-)
Hello All, This solution has worked for me..
editor = new wysihtml5.Editor("description", { toolbar: "textareaId", stylesheets: ["http://yui.yahooapis.com/2.9.0/build/reset/reset-min.css", "css/editor.css"], parserRules: wysihtml5ParserRules }); var composer = editor.composer; composer.setValue("Inser Your HTML Here");
I had a few issues with this until I found this solutions
$('iframe').contents().find('.wysihtml5-editor').html('your new content here');
fdsfds
thanks @gabisajr that was the only solution for me