Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting onChange events from a CKEditor using Jquery

I'm working with the CKEditor and jQuery and I'd like to toggle a flag to true whenever a user changes the value of a field. One of those fields is a CKEditor instance.

All the textareas that have the "wysiwyg" class get converted to CKEditors but somehow the $('.wysiwyg').change() event never gets detected. I did some googling but the keyword combination seems to bring up nothing but irrelevant results (my google-fu sucks).

Thanks for any help :)

Edit:

for (var i in CKEDITOR.instances) {         CKEDITOR.instances[i].on('click', function() {alert('test 1 2 3')});     } 

I tried the code above and it doesn't work. It doesn't give me an error meaning that it finds the CKEditor objects but for some reason the listener isn't attached to it?

Also, if I replace the event attachment with just alert(CKEDITOR.instances[i].name); it'll alert the name of my textarea so I know I'm not trying to attach the click event to nothing :)

like image 456
Gazillion Avatar asked Feb 28 '11 14:02

Gazillion


People also ask

Does CKEditor use jQuery?

Thanks to these changes CKEditor 4 automatically works with the official jQuery Form Plugin for Ajax-based forms. It does not require any action from the developer's side to support it.

How do I get CKEditor data?

If you need to get the actual data from CKEditor 4 at any moment using JavaScript, use the editor. getData() method as described above.


1 Answers

You can get a plugin (and an explanation about what things are detected as changes) in this post: http://alfonsoml.blogspot.com/2011/03/onchange-event-for-ckeditor.html so you can do things like

for (var i in CKEDITOR.instances) {         CKEDITOR.instances[i].on('change', function() {alert('test 1 2 3')});     } 
like image 55
AlfonsoML Avatar answered Sep 30 '22 12:09

AlfonsoML