michaelpapworth / tinymce-knockout-binding

A KnockoutJS custom binding that applies a TinyMCE Editor to the bound HTML element
MIT License
39 stars 19 forks source link

Binding to injected HTML #14

Closed gordon-matt closed 9 years ago

gordon-matt commented 9 years ago

Excellent binding. I have been using this for a while now and it does the job quite nicely. However, I have just come across a problem with it not binding properly under special circumstances. I am injecting portions of HTML into my main view and rebinding everything. See the answer to my own question on StackOverflow here:

http://stackoverflow.com/questions/25944636/angularjs-how-to-get-properties-from-arbitrary-type?noredirect=1#comment40636363_25944636.

Ignore the title of the post; I started off using AngularJS, but moved to Knockout. The answer I posted in the above link shows my implementation. The problem is that this tinymce binding only works the first time. After that, when I clear the HTML from the div and repopulate and bind it again (with another record), then the whole textarea is missing... got nothing there at all.

I have confirmed this is definitely the binding and not knockout itself, because if I change

data_bind = "wysiwyg: bodyContent, wysiwygConfig: tinyMCEConfig"

to just:

data_bind = "value: bodyContent"

then it works fine; I can see the bodyContent no matter how many times I clear the div and inject something else.

Do you think you can fix this?

gordon-matt commented 9 years ago

Ignore, I solved the issue. by changing my code a little... it seems I was forgetting to remove previous script tags and I should have called ko.cleanNode(); before injecting the new HTML. It's working fine now - not a bug with your binding as I had at first suspected.