How do I use the Quill event for text-change?
How do I use the Quill event for text-change?
I would like to listen to the quill text-change event but I am not sure how to do that. In my editor, I am setting the type of one of my fields to quill and the quill editor displays when the editor is open. Could someone provide me with an example of how to get the quill instance so I can use the text-change event? The error I get is quill is not defined.
quill.on('text-change', function () {
if (messageHtml.value && messageHtmlError.error()) {
messageHtmlError.error('');
}
});
I want to be able to run this when my editor is open.
In the documentation, https://editor.datatables.net/plug-ins/field-type/editor.quill, under Methods it says: quill: Get the Quill instance used for this field, so you can add additional modules, or perform other API operations on it directly.
Answers
I'm not sure what you want to do in this event. Maybe there is an Editor event you can use,
submitComplete
for example.The docs have this:
It looks like you will need to use the
field()
API to get the field then chain the quill method. Something like this:Kevin
I tried the above code snippet. It looks like the event fires when the editor form is open, likely do to the plugin setting the text to the field value. Then fires when changes are made. So it may fire twice for you when editing.
Kevin
Possibly it might be better to update the quill plugin to turn on the
text-change
event after the field value is set. When the field is submitted turn off the event. Something like this:Note the
text-change
event fires each time something is typed in the quill field.Kevin
@kthorngren Thank you for your help! Using the field api was exactly what I needed to get this working.