Trying to call the keyup function on ckeditor
Asked Answered
D

3

7

I had a text area that has been replaced by ckeditor. I had some jquery to listen to the textarea input:

$('.formanswer').keyup(function () {
        LimitText($(this), $(this).attr('data-maxlength'));
});

the limit text method just limits the text input.

so now the text area tag looks like this:

<textarea class="formanswer" rows="10" cols="2" id="response_<%: animal.AnimalId.ToString() %>" name="animalresponse" data-maxlength="<%: animal.AnimalMaxLength.ToString() %>"><%: animal.AnimalResponse %></textarea>

I am trying to do the same thing but with the the ckeditor... I have had a look at the documentation: http://docs.ckeditor.com/#!/guide/dev_jquery

I tried a few different things to have that event on the editor instance but it hasn't worked...I am using the javascript implenentation, not the asp net one.

Doordie answered 4/2, 2014 at 14:38 Comment(3)
I have just found this: ckeditor.com/forums/CKEditor-3.x/handling-keyup-event - going to try itDoordie
Guess I didn't pay as much attention to the documentation as I thought: docs.ckeditor.com/#!/api/CKEDITOR.event-method-on - going to try itDoordie
I tried this and it is helpful too: https://mcmap.net/q/1479085/-ckeditor-add-quot-keyup-quot-eventFuzee
D
4

given the name of the CKEditor is: editor the solutions is:

var e = CKEditor.instances['editor']

e.on( 'keyup', function( event ) {
    alert( e.getData() );
});

in this particular solution, I am just alerting the contents of the editor.

Doordie answered 11/2, 2014 at 20:58 Comment(1)
'keyup' event does not fire in inline editor, but 'key' doesCompurgation
F
6

actually only this is working with ckeditor 4, where editor is the id of textarea:

CKEDITOR.instances.editor.on('key', function(e) {
    var self = this;

    setTimeout(function() {
        console.log(self.getData());
    }, 10);
});

getData returns the value currently inputed. Delayed, because otherwise last value would be missing.

Foresheet answered 11/5, 2016 at 13:49 Comment(0)
D
4

given the name of the CKEditor is: editor the solutions is:

var e = CKEditor.instances['editor']

e.on( 'keyup', function( event ) {
    alert( e.getData() );
});

in this particular solution, I am just alerting the contents of the editor.

Doordie answered 11/2, 2014 at 20:58 Comment(1)
'keyup' event does not fire in inline editor, but 'key' doesCompurgation
I
3

This will surely work on Ck Editor 4.x and up

  CKEDITOR.on('instanceCreated', function (e) {
    e.editor.on('change', function (event) {
 var value = CKEDITOR.instances['TestArea_id'].getData();//Value of Editor
});
});
Irreplaceable answered 15/11, 2016 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.