I am dynamically instantiating the QuillJS editor on a click event of an element in the DOM. So my requirement is that once the user is done with the editing for that element, he/she should be able to close the editor. Currently, I do not see any close method in the quill API. The enable/disable API methods won't work for me as I want to close the editor completely and show the user the same view he/she had before seeing the quill editor but of course with the saved changes.
The demo of this can be seen here
https://codepen.io/curiousdj/pen/eEjbPK
const options = { theme: "snow" };
var divs = document.getElementsByTagName("div");
var initializeQuill = function (e){
if(!this.quill){
console.log(e);
this.target = event.currentTarget;
this.quill = new Quill(this.target, options);
this.target.children[0].onclick = function(et) { et.preventDefault(); };
this.target.children[0].onblur = function(l) {
l.target.parentElement.quill.close;
};
}
this.quill.focus();
e.stopPropagation();
e.preventDefault();
}
for(var i = 0; i < divs.length; i++){
divs[i].onclick = initializeQuill;
}
quill. disable() should do the trick.
in React Quill 1.3. 5, you can add the readOnly prop as true. It will disable your editor like input tag when disabled.
Quill Rich Text Editor Quill is a free, open source WYSIWYG editor built for the modern web. With its modular architecture and expressive API, it is completely customizable to fit any need.
'click #editNote': (e, t) -> note = t.find '.container' console.log note basicEditor = new Quill (note) Then once the user clicks save I want to be able to disable the Quill editor.
When the user clicks edit I turn the template into an editable Quill editor like so: 'click #editNote': (e, t) -> note = t.find '.container' console.log note basicEditor = new Quill (note)
Quill requires a container where the editor will be appended. You can pass in either a CSS selector or a DOM object. To configure Quill, pass in an options object: The following keys are recognized: DOM Element or a CSS selector for a DOM Element, within which the editor’s ui elements (i.e. tooltips, etc.) should be confined.
QuillJS is a beautiful open-source text editor for web applications. In this tutorial I’m going to show you how to configure it, and in the second step we will get the typed text.
I'd advise either:
I've updated your pen here to give an example of the second option with basic changes
.ql-editor {
padding:0;
line-height:inherit;
}
.ql-editor p {
margin-bottom:10px;
}
.ql-toolbar {
display:none;
}
.ql-container.ql-snow {
border:none;
font-family:inherit;
font-size:inherit;
}
This work for me:
function destory_editor(selector){
if($(selector)[0])
{
var content = $(selector).find('.ql-editor').html();
$(selector).html(content);
$(selector).siblings('.ql-toolbar').remove();
$(selector + " *[class*='ql-']").removeClass (function (index, css) {
return (css.match (/(^|\s)ql-\S+/g) || []).join(' ');
});
$(selector + "[class*='ql-']").removeClass (function (index, css) {
return (css.match (/(^|\s)ql-\S+/g) || []).join(' ');
});
}
else
{
console.error('editor not exists');
}
}
To use it just call:
destory_editor('.editor');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With