Estoy accediendo a un iframe a través de fancybox 3 con múltiples ckeditor . Está funcionando bien, pero quiero rastrear si un usuario ha ingresado algo en los cuadros de texto para poder cambiar el botón del cuadro elegante y darles una alerta una vez que presionen cerrar. Este es mi código JS en la página iframe:
window.editors = {}; document.querySelectorAll( '.editor' ).forEach( ( node, index ) => { ClassicEditor .create( node, { removePlugins: ['Heading', 'BlockQuote', 'CKFinderUploadAdapter', 'CKFinder', 'EasyImage', 'Image', 'ImageCaption', 'ImageStyle', 'ImageToolbar', 'ImageUpload', 'MediaEmbed'], } ) .then( newEditor => { window.editors[ index ] = newEditor; } ); editors[ index ].document.on( 'change', () => { console.log( 'Alert: The document has changed!, are you sure you want to close without saving?' ); } ); } );Pero me está dando un error:
ifram.php:1070 Uncaught TypeError: Cannot read properties of undefined (reading 'document') at ifram.php:1070 at NodeList.forEach (<anonymous>) at ifram.php:1060También intenté sacar esto de la función document.querySelectorAll()
editors.document.on( 'change', () => { console.log( 'Alert: The document has changed!, are you sure you want to close without saving?' ); } ); Pero me dio otro error: Uncaught TypeError: Cannot read properties of undefined (reading 'on')
Podría usar el documento newEditor.model.document.on('change:data')
<script src="https://cdn.ckeditor.com/ckeditor5/30.0.0/classic/ckeditor.js"></script> <textarea class="editor"></textarea> <script> window.editors = {}; document.querySelectorAll( '.editor' ).forEach( ( node, index ) => { ClassicEditor .create( node, { removePlugins: ['Heading', 'BlockQuote', 'CKFinderUploadAdapter', 'CKFinder', 'EasyImage', 'Image', 'ImageCaption', 'ImageStyle', 'ImageToolbar', 'ImageUpload', 'MediaEmbed'], } ) .then( newEditor => { window.editors[ index ] = newEditor; newEditor.model.document.on('change:data', ()=> { console.log( 'Alert: The document has changed!, are you sure you want to close without saving?' ); }); } ); }); </script>