Cutting off the final character in CKEditor for AngularJS

I have come across an issue with my web page that utilizes CKEditor for creating message edit panes. The problem arises when I try to send a message and the content retrieved from CKEditor is missing the last letter.

Below is a snippet of what I believe to be the relevant code in the application:

appDirectives.directive('ckEditor', function() {
    return {
        require : '?ngModel',
        link : function(scope, elm, attr, ngModel) {
            var ck = CKEDITOR.replace(elm[0], {
                toolbar: [
                    { name: 'basicstyles', items: [ 'Bold', 'Italic' ] },
                    { name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste' ] },
                    { name: 'links', items: [ 'Link', 'Unlink' ] }
                ],
                removePlugins: 'elementspath'
            });

            if (!ngModel)
                return;

            ck.on('instanceReady', function() {
                ck.setData(ngModel.$viewValue);
            });

            function updateModel() {
                scope.$apply(function() {
                    ngModel.$setViewValue(ck.getData());
                });
            }

            ck.on('change', updateModel);
            ck.on('key', updateModel);
            ck.on('dataReady', updateModel);

            ngModel.$render = function(value) {
                ck.setData(ngModel.$viewValue);
            };
        }
    };
});

As well as the corresponding HTML:

<div>
    <div class="actions">
        <button class="sendButton" ng-click="send()" type="button">
            Send
        </button>
    </div>
    <div>
    {{message.content | warnIfContentMaxExceeded}}
    </div>
    <div class="body">
       <textarea ck-editor="" id="contentEditor" 
                 name="contentEditor" rows="10" cols="60" 
                 ng-model="message.content" 
                 value="message.content"></textarea>
    </div>
</div>

And here's a glimpse at the controller:

$scope.send = function() {
    var msg = $scope.message;
    // ...
}

Upon inspecting my editor setup directive, I suspect that ck.on('change', updateModel); might not trigger immediately after each character input. However, clicking away from the editing pane does not seem to invoke any change event. Am I missing something in the configuration/code?

Do you reckon upgrading to a newer version of CKEditor would resolve this issue?

Current software versions in use:

  • AngularJS :: 1.3.4
  • ng-ckeditor :: 0.2 (ckeditor 4.1.2)

Answer №1

After conducting my own extensive research, I have discovered that updating to CKEditor 4.4.6 effectively resolves the issue at hand.

It is likely that a glitch present in the previous version has been fixed between versions 4.1.2 and 4.4.6.

Please Note - While upgrading may be the optimal solution for most users, the response provided by @Nenotlep still functions well with this particular version of CKEditor. As a result, I am acknowledging their answer and supplementing it with this additional insight.

Answer №2

To determine if updateModel is being triggered too frequently, consider implementing a small throttle mechanism. I have utilized this approach in the past for handling scrolling events and CKE events.

You could try using an untested method like the following:

var throttle = -1;
function updateModelThrottle() {
    if (throttle !== -1) {
        if (console && console.log) { console.log("Throttled!"); }
        clearTimeout(throttle);
    }
    throttle = setTimeout(updateModel, 500);
}
function updateModel() {
    if (console && console.log) { console.log("Firing!"); }
    scope.$apply(function() {
        ngModel.$setViewValue(ck.getData());
        throttle = -1;
    });
}

ck.on('change', updateModelThrottle);
ck.on('key', updateModelThrottle);
ck.on('dataReady', updateModelThrottle);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Assign the ngClick event handler to the capturing phase

Can the ngClick event handler be configured to work in the capturing phase, as discussed in this informative article? I am interested in stopping events from propagating down to child elements and then back up again when a specific condition is met for t ...

What steps can be taken to ensure Vue application admin page contents are not displayed without proper authentication?

By implementing role-based authentication in Vue app, we can efficiently manage routes and components visibility between regular users and administrators. As the number of roles increases, the application size grows, making it challenging to control CRUD ...

What steps can I take to resolve a dependency update causing issues in my code?

My program stopped working after updating one of the dependencies and kept throwing the same error. Usually, when I run 'ng serve' in my project everything works fine, but after updating Chartist, I encountered this error: An unhandled exception ...

What is the best way to retrieve a promise from several promises?

Every time I check the console, I see the following: teamsUpdated2 addUserToProjects deleteUserFromProjects However, they should be displayed in a different order. var result = teamService.addOrDeleteUser(userId, newTeams, deleteTeams); result.then(fun ...

What is the best way to continuously loop an image from left to right and right to left indefinitely using JavaScript?

As part of the challenge, I am tasked with creating a Pacman game using HTML, CSS, and JavaScript. One key aspect is to control the movement of the ghosts throughout the game. However, I am facing an issue with the current function that controls the ghost& ...

Embed a function within a string literal and pass it to another component

Is there a way to pass a function defined in actions to an element? Reducer case 'UPDATE_HEADER': return Object.assign({}, state, { headerChildren: state.headerChildren.concat([action.child]) }); Action.js export const deleteH ...

Exploring the functionality of $timeout in AngularJS

Can you explain the functionality of $timeout in AngularJS and how it sets itself apart from traditional setTimeout()? ...

Stop the change event from occurring on a textarea when the user clicks on an external cancel button

In a particular scenario, there is a textarea with an autosave feature triggered by the change event. When the textarea is focused on, Save and Cancel buttons appear at the bottom, providing users with options in case they prefer not to simply click outsid ...

Once the grunt build process is complete, execute "heroku run fileName" to launch the

In order to gain a deeper understanding of Heroku scheduling, I decided to delve into an informative post on the topic and followed the instructions provided to build the app. The highlight of the post was when I successfully executed heroku run numCheck a ...

Concatenating an unlimited amount of arrays containing Javascript objects

I currently have an array of Groups where each Group contains multiple Users. My goal is to retrieve all the unique Users associated with a given array of Groups. Here is my current approach: let actor = await User.query().findById(req.user.id).eager( ...

Attempting to reset the altered values proves ineffective in different Ctrl instances within AngularJS

I'm feeling a bit disoriented regarding my current issue. The scenario involves two views and a controller that interact with a service. The first view consists of a table list containing items loaded from a WebAPI. The service sends requests to the s ...

What are the steps to recursively transform a JavaScript object?

I am currently working on recursively transforming a JavaScript object, but I have encountered an issue. The problem is: if any object key has exactly two properties - 'label' and 'value', then the value should change to the label only ...

Leveraging jQuery to Avoid Memory Leaks

After utilizing jQuery for a couple of months and delving into Javascript memory leaks for several days, I have two concerns related to memory leaks and jQuery: When I bind events (using .bind()) in jQuery, do I need to unbind them (.unbind()) before l ...

Chat lines in Chrome displaying double entries - troubleshooting needed

I developed a chat plugin for my website with a simple HTML structure: <div id="div_chat"> <ul id="ul_chat"> </ul> </div> <div id="div_inputchatline"> <input type="text" id="input_chatline" name="input_chatline" val ...

How can I prevent my mouse click from being overridden by my mouse hover?

Currently, I am developing a Sudoku game using JavaScript and facing some challenges with mouse events. My goal is to enable users to hover over a square and have it change color, as well as click on a square to highlight the entire row, column, and quadra ...

Tips for Troubleshooting External Evaluation Scripts

For a specific example, take a look at the haystack.js script from How Big is Your Haystack? I've been searching for a solution and it seems that using the //# sourceURL=name.js comment is the way to go. However, I am struggling with the process of a ...

What is the best way to send AJAX post data to a Node.js server?

I am currently facing an issue with passing a unique ID object back to the server side using Ajax after making an API call. I need help figuring out what might be going wrong in my code. This is the client side code snippet where I loop through a JavaScri ...

The issue of linking .then() functions

I've been struggling to grasp the concept of Promises/then-ables for a while now. Currently, I am working with NextJS. My goal is to chain together the following steps: Retrieve data from an API Save the data Modify the data to create a component (w ...

Encountering module error 'internal/fs' after updating to Node 7

We have encountered some challenges after attempting to update our build server to node v7.0.0. Specifically, the application build task fails at the "bower_concat" step with the following error message: Loading "bower-concat.js" tasks...ERROR Error: Cann ...

Tips for maintaining an active class on parent nav items in NextJS when navigating dynamic routes

In my nextjs-application, I've implemented a Navbar showcasing several navitems: Navbar.tsx: const Navbar = ({ navitems }) => { return ( <div> {navitems?.map((navitem, idx) => ( <NavItem key={idx} navitem={nav ...