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

What steps should I take to create a plugin for a library if defining it as a peerDependency does not provide a specific implementation for me to work with?

Requirements for My Plugin: I'm currently in the process of developing a new plugin that is dependent on popularLibrary.js. Here are the key points about my plugin: It will not function properly if popularLibrary.js is missing. It is designed to wo ...

The button on my VUE 3 quiz app is not changing to 'Finish' when I reach the final question

Struggling with my Vue 3 quiz app - everything works perfectly until I reach the last question. The button text should change to 'Finish' once the final question is loaded. Despite hours of searching and even using copilot, I still can't fin ...

Unit testing in JavaScript has its limitations, one of which is the inability to verify if a

Currently, I am working with an Angular application that includes a simple directive called animate. My goal is to use Jasmine to verify if the slideDown method is being called. Below is the current setup of my directive: animateDirective var animate = f ...

Tips for transmitting form information in a fetch call

As I was developing a nodejs server, I encountered an issue with the POST call that involves sending form input data to a remote server. Despite everything else working fine, the form data was not being received by the server. Below is the code snippet in ...

Using the spread operator in a component's render function could potentially lead to an endless update loop

Although this issue has been addressed before in a discussion about the "You may have an infinite update loop in a component render function" warning in Vue component, the solution provided did not resolve my problem. I am seeking assistance to ...

Utilizing the json_encode() function in PHP and JSON.parse() method in JavaScript for handling file data interchange

Utilizing json_encode() in PHP to store an array in a file, then leveraging JSON.parse() in JavaScript on the client side to read the json encoded file and pass it as an array to a sorting algorithm: The result of my json_encode() operation in the ...

Issue finding a route based on dates

Hey everyone, I'm working on a feature where I need to fetch tasks made by a user within a specific date range provided by the user. However, I am facing some issues with getting the date and routing it. Here is the URL format that I am trying to work ...

Is there a way to create an image gallery layout similar to Pinterest using CSS?

I am currently developing a dynamic PHP gallery that will feature thumbnails with the same width but varying heights. These thumbnails will be arranged from left to right, so I would prefer not to use a traditional five-column layout. I suspect that achiev ...

Is the reference to a variable within an array maintained by JavaScript?

I'm working with react code and using the find() method to select an item from an array. When I retrieve an item from the array, is JavaScript copying the item or returning a reference? EDIT: The items in my array are objects, such as [{id: 12, name ...

Efficiently Encoding Still Image Data for NextJS

Currently, I am experimenting with a completely static method in my new Next.js v12 project. I am creating 5-6 data files to use with getStaticProps. Here is an example of one of the data file structures (they are all similar): import SqAshland1 from &apos ...

Implementing JavaScript Code in TypeScript

Every JavaScript code should also be valid in TypeScript, but when attempting to run the following code snippet below, an error is triggered. Could someone convert this JavaScript code into TypeScript? Error: 20:9 - TS2531 Error: Object is possibly 'z ...

Having trouble with VueJS ref not preventing the default form action on submit?

Within my <script> tag, I currently have the following code: render(createElement) { return createElement("form", {ref: "formEl" , on: {submit: this.handleSubmit} }, [ <insert create form inputs here> ]); } handleSubmit(e) { ...

Unity of MEAN Assemblage

My current project involves working with the MEAN stack, particularly using MEAN.js. Although the documentation provides a good explanation of everything, I am facing a challenge when it comes to associating one entity or Model with another. To give an ex ...

What is the best way to move between websites or pages without having to reload the current page using a selector?

Have you ever wondered how to create a webpage where users can navigate to other websites or pages without seeing their address, simply by selecting from a drop-down menu? Take a look at this example. Another similar example can be found here. When visit ...

How can I change the background color of a parent div when hovering over a child element using JavaScript

I am working on a task that involves three colored boxes within a div, each with a different color. The goal is to change the background-color of the parent div to match the color of the box being hovered over. CSS: .t1_colors { float: left; wid ...

Attempting to design a customized tooltip for an SVG element embedded within the HTML code

Recently, I've delved into Js with the goal of creating an interactive pronunciation guide using inline svg. If you're curious to see what I've done so far, check it out here. My current focus is on incorporating basic styled tooltips that ...

Attempting to convert PHP tables into PDF format by utilizing jsPDF-auto-table to generate a beautifully structured PDF file containing the results of a PHP query with multiple records

I'm new to stackoverflow but I find myself visiting it regularly for helpful tips. I've taken some code from the simple.html file that comes with the jsPDF auto-table plugin. However, I'm having trouble making it work with data generated by ...

Countdown malfunction: wrong date displayed

Utilizing the Countdownjs library in my project is resulting in an incorrect day count. Incorporating AngularJS, here is the custom directive I've implemented for the countdown: .directive('tempoPercorrido', function($interval){ ret ...

Adjust the size of the font in your Bootstrap Table

I've been utilizing the Bootstrap table feature and it's been fantastic, but I've encountered an issue with changing the font size. I've referred to the example on , however no matter what adjustments I make to the size, it doesn' ...

When setting an attribute on load, Javascript may not properly apply the change to the attribute

I designed a webpage where images have a fade-in effect using a CSS class. Initially, 4 images load with the desired effect. However, I encounter an issue when trying to apply the same effect to a new image that appears upon clicking a button. Below is th ...