Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8062911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:50:14+00:00 2026-06-05T10:50:14+00:00

I have a situation involving KnockoutJS & CKEditor. Basically we’ve got part of our

  • 0

I have a situation involving KnockoutJS & CKEditor.

Basically we’ve got part of our site that is ‘single page’ app style, currently it just involves 2 pages but will likely expand over time, currently it’s just a ‘listings’ page and a ‘manage’ page for the items in the list.

The manage page itself requires some sort of rich text editor, we’ve gone with CKEditor for a company wide solution.

Because these 2 pages are ‘single page’ style obviously CKEditor can’t register against the manage elements because they aren’t there on page load – simple enough problem to fix. So as a sample I attached CKEditor on a click event which worked great. The next problem was that then the Knockout observables that had been setup weren’t getting updated because CKEditor doesn’t actually modify the textarea it’s attached too it creates all these div’s/html elements that you actually edit.

After a bit of googleing I found an example of someone doing this with TinyMCE – http://jsfiddle.net/rniemeyer/GwkRQ/ so I thought I could adapt something similar to this for CKEditor.

Currently I’m quite close to having a working solution, I’ve got it initialising and updating the correct observables using this technique (I’ll post code at the bottom) and even posting back to the server correctly – fantastic.

The problem I’m currently experiencing is with the ‘Single Page’ app part and the reinitialisation of CKEditor.

Basically what happens is you can click from list to manage then save (which goes back to the list page) then when you go to another ‘manage’ the CKEditor is initialised but it doesn’t have any values in it, I’ve checked the update code (below) and ‘value’ definitely has the correct value but it’s not getting pushed through to the CKEditor itself.

Perhaps it’s a lack of understanding about the flow/initialisation process for CKEditor or a lack of understanding about knockout bindings or perhaps it’s a problem with the framework that’s been setup for our single page app – I’m not sure.

Here is the code:

//Test one for ckeditor
ko.bindingHandlers.ckeditor = {
    init: function (element, valueAccessor, allBindingsAccessor, context) {
        var options = allBindingsAccessor().ckeditorOptions || {};
        var modelValue = valueAccessor();

        $(element).ckeditor();

        var editor = $(element).ckeditorGet();

        //handle edits made in the editor
        editor.on('blur', function (e) {
            var self = this;
            if (ko.isWriteableObservable(self)) {
                self($(e.listenerData).val());
            }
        }, modelValue, element);


        //handle destroying an editor (based on what jQuery plugin does)
        ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
            var existingEditor = CKEDITOR.instances[element.name];
            existingEditor.destroy(true);
        });
    },
    update: function (element, valueAccessor, allBindingsAccessor, context) {
        //handle programmatic updates to the observable
        var value = ko.utils.unwrapObservable(valueAccessor());
        $(element).html(value);
    }
};

So in the HTML it’s a fairly standard knockout ‘data-bind: ckeditor’ that applyies the bindings for it when the ViewModel is initialised.

I’ve put debugger; in the code to see the flow, it looks like when I load the first time it calls init, then update, when I go in the second time it hits the ko.utils.domNodeDisposal to dispose of the elements.

I’ve tried not destroying it which CKEditor then complains that something already exists with that name. I’ve tried not destroying it and checking for if it exists and initialising if it doesn’t – that works the first time but the second time we have no CKEditor.

I figure there’s just one thing I’m missing that will make it work but I’ve exhausted all options.

Does anyone have any knowledge on integrating these 3 things that can help me out?

Are there any knockout experts out there that might be able to help me out?

Any help would be much appreciated.

MD

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:50:16+00:00Added an answer on June 5, 2026 at 10:50 am

    For anyone interested I sorted it:

    All it was was a basic order of execution, I just needed to set the value to the textarea html before it got initialised.

    Note this uses a jquery adaptor extension to do the .ckeditor() on the element.

    There is probably also a better way to do the ‘blur’ part.

    This extension also doesn’t work with options at the moment but that should be quite simple in comparison.

    ko.bindingHandlers.ckeditor = {
        init: function (element, valueAccessor, allBindingsAccessor, context) {
            var options = allBindingsAccessor().ckeditorOptions || {};
            var modelValue = valueAccessor();
            var value = ko.utils.unwrapObservable(valueAccessor());
    
            $(element).html(value);
            $(element).ckeditor();
    
            var editor = $(element).ckeditorGet();
    
            //handle edits made in the editor
    
            editor.on('blur', function (e) {
                var self = this;
                if (ko.isWriteableObservable(self)) {
                    self($(e.listenerData).val());
                }
            }, modelValue, element);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation, where running a query that filters by an indexed column in
We have situation where say we have four engineers that are working on software
I have situation where I need to make sure that user has completed certain
I have a common database joining situation involving three tables. One table, A, is
I have a situation I'm trying to cope with involving my company's SVN server.
The situation: I have a piece of code that works when compiled for 32-bits
I have a weird situation involving the need of a double inner join. I
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation in which I read a record from a database. And if
I have situation where I need to change the order of the columns/adding new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.