bootstrap-wysihtml5 icon indicating copy to clipboard operation
bootstrap-wysihtml5 copied to clipboard

How to populate editor once initialised via jquery

Open oller opened this issue 13 years ago • 7 comments

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?

oller avatar Jun 22 '12 11:06 oller

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

evadnoob avatar Jun 25 '12 18:06 evadnoob

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!

oller avatar Jun 25 '12 20:06 oller

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! :-)

evadnoob avatar Jun 25 '12 21:06 evadnoob

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

abhasbaghel avatar Jun 23 '14 13:06 abhasbaghel

I had a few issues with this until I found this solutions

$('iframe').contents().find('.wysihtml5-editor').html('your new content here');

gabisajr avatar Aug 20 '16 17:08 gabisajr

fdsfds

kimhongheng avatar Jan 07 '18 13:01 kimhongheng

thanks @gabisajr that was the only solution for me

DanielnetoDotCom avatar Feb 23 '18 11:02 DanielnetoDotCom