Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout JS issue with tinymce textarea

Javascript

var tiny_options = {
    height: 120,
    width: 300,
    mode: 'textareas',
    theme: 'advanced',
    theme_advanced_buttons1: 'bold,italic,underline',
    theme_advanced_buttons2: '',
    theme_advanced_fonts: 'Arial=arial,helvetica,sans-serif,Courier New=courier new,courier,monospace,Georgia=georgia,times new roman,times,serif,Tahoma=tahoma,arial,helvetica,sans-serif,Times=times new roman,times,serif,Verdana=verdana,arial,helvetica,sans-serif',
    theme_advanced_toolbar_location: 'top',
    theme_advanced_toolbar_align: 'left'
};


//tinymce.init(tiny_options); // Please, remove comment to activate the tinymce

var initData = function (d) {
    this.id = ko.observable(d.id);
    this.text = ko.observable(d.text);
};

var viewModel = function () {
    var self = this,
        data = [{
            id: 1,
            text: 'some text 1'
        }, {
            id: 2,
            text: 'some text 2'
        }];

    self.dataSet = ko.observableArray([]);

    $.each(data, function (i, d) {
        self.dataSet.push(new initData(d));
    });
};

var model = new viewModel();
ko.applyBindings(model);

UI

<!-- ko foreach : dataSet -->
<br>
<textarea data-bind="value: text, valueUpdate : 'change'"></textarea>
<br>
<!-- /ko -->

Link to Demo


Above, code is working fine, i.e. model data is updating nicely without tinymce binding, but when I activate the tinymce, view model observable is not updating. I tried this also, but no result.

So, Please help me to configure, how can I update the view model observables using tinymce binding?

like image 861
The System Restart Avatar asked Dec 05 '25 03:12

The System Restart


1 Answers

Looks like you need a custom binding that will bind up the value and apply the TinyMCE Editor to your <textarea>. The net result looking something like this;

<textarea data-bind="wysiwyg: text"></textarea>

Give the one I've put together on Github a try https://github.com/michaelpapworth/tinymce-knockout-binding

like image 148
Michael Papworth Avatar answered Dec 07 '25 16:12

Michael Papworth