-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect changes in the editor content #996
Comments
CKEditor 5 provides an event which is fired every time changes happen to the editor's content. See We don't provide a way to check if the editor "is dirty", however it would be quite easy to write it by yourself, either as a plugin or just code initialized after the editor has been created (in the First, after the editor is init'ed, set |
EDIT for the above comment. In ckeditor5@v11.0.0 (ckeditor5-engine@10.2.0) we introduced a new event: You can use it like this: editor.model.document.on( 'change:data', () => {
console.log( 'The data has changed!' );
} ); |
Sorry for my ignorance but if I was initialising the editor like this:
...how/where would I apply the code you've suggested above? I'm new to this and I'm struggling with putting any answers I find into context and getting them working! (Also, I can't seem to get my code here to showing in a block! Argh!) |
Hi @helenburns. $(document).ready( function() {
InlineEditor .create( document.querySelector( '#editor' ), {
placeholder: 'General page text...'
} )
.then( editor => {
editor.model.document.on( 'change:data', () => {
console.log( 'The data has changed!' );
} );
} )
.catch( error => { console.error( error ); } );
} );
Put your code between ``` 😉 |
Oh thank you so much!! It's so easy for people like me, who know a bit but not quite enough, to get confused and switch off to the amazing tools out there like CKEditor when all it takes is a little time from someone to explain a bit. Thanks so much. |
How can I changed data? |
The answer you're looking for is "editor.getData()"... `
` |
The dirty state can be tracked via the callback see ckeditor/ckeditor5#996 (comment)
Is this a bug report or feature request? (choose one)
🆕 Feature request
💻 Version of CKEditor
ckeditor5-build-classic-1.0.0-beta.3
Request
As a developer I would like to have the possibility to detect that the editor content contains changes and I also need to be able to reset the "dirty state" like in CKEditor4.
Here is the CKEditor4 API documentation:
https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#method-checkDirty
https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#method-resetDirty
The text was updated successfully, but these errors were encountered: