Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to call the keyup function on ckeditor

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.

like image 430
user2405469 Avatar asked Feb 04 '14 14:02

user2405469


2 Answers

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.

like image 110
Titenis Avatar answered Sep 17 '22 18:09

Titenis


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.

like image 43
user2405469 Avatar answered Sep 19 '22 18:09

user2405469