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

Knockout Event's Not working #10

Open ghost opened 10 years ago

ghost commented 10 years ago

It seems that the knockout events are not working. I have a change event setup to call an ajax function if the value changed but its not working. Any help?

<textarea class="form-control" style="height: 100px; width: 100px;" data-bind="wysiwyg: specificationText, event: { change: $parent.itemChanged }"></textarea>
michaelpapworth commented 10 years ago

A good question. I'm certainly happy look into the feasibility of this, since it seems logical to ensure that all events wire up. However, when dealing with the change event specifically you can still achieve this. Take a look at my tutorial on Working with Extensions. You can write an extension that gets called each time the editor changes which in turn calls your function. Something like this;

(function( wysiwyg ) {

    wysiwyg.extensions['mycustomextension'] = function( editor, args, allBindings, bindingContext ) {
        bindingContext.$parent.itemChanged();
    };

})( ko.bindingHandlers['wysiwyg'] );

Hope this helps.

ghost commented 10 years ago

Thank you this did work!

I have another question. This seems to get called multiple times while clicking into the text-area making my change then clicking out. Anyway to only call this fucntion when the value changed or like on blur or something? I don't see a point of calling it on focus. Thanks for your help.