-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Can't find the "setHTML" function. #1449
Comments
Hmmm.... it looks like this function is perhaps not in the latest version of Quill? How then can I set the HTML programatically? I'm trying to load the initial data into the control upon load. thanks! |
For those who might come later on....... The actual problem that I was trying to solve is how to save data from quill and restore it next time quill is loaded. I assumed that the right way to do this was to save the HTML and then write it back somehow. Further learning appears to indicate that in fact the correct way to load and save data is to save quills "delta" object in your database or whereever and this delta can be reloaded via "setContent()" |
Alternatively, can save and load html with getting the innerHTML of the quill-editor to save, and then restore by putting this html in between the editor containers html tags before initializing that container with Quill.
|
In my opinion methods to Of course with notice that using these methods is bad practice. But It is confusing if it is not described at all. |
The quill api is indeed confusing on this. How to do implement a proper edit, save, reload use case is not clear at all from the documentation. I think the fundamental confusion is that many users want to treat this like a normal input component that has a value that you can get/set. IMHO a reasonable expectation but it seems quill does not work that way. I understand why (security) but it makes it needlessly hard to use. After a bit of googling, I have slightly better workaround that seems to beat some sense into this API.
The dangerouslyPasteHTML seems intended to protect users against script injection. Understandable but it kept getting extra new lines when I modified innerHtml directly. Of course, our server of course cleans up the html and validates stuff. So, there is zero risk with this. I understand that Deltas are really nice for all sorts of advanced things we don't need. I also think storing that in a DB is a bad idea. I insist on something standardized like markdown or sanitized html without leaking implementation details about whatever was used for editing. |
I use Quill with Vue and I need to store html in db because often I just want to show formatted rich text (not editable). So I just paste it in div.ql-container > div.ql-editor. And sometimes I save the initial content and then I want to "Discard Changes" and set editor content back to the initial. So the setHtml function that would not trigger text-change event would be very helpful. Now I have to do something ugly like this: // when the Vue component with Quill editor is mouted
this.$refs.editor.innerHTML = this.value
this.quill = new Quill(this.$refs.editor, {})
this.quill.on('text-change', ()=>{
this.notUserInput = true
this.$emit('input', this.$el.querySelector('.ql-editor').innerHTML)
})
// and then watching for external changes
value(val){
if (!this.notUserInput){
this.$el.querySelector('.ql-editor').innerHTML = val
} else {
this.notUserInput = false
}
} |
I don't see why that should yield any bad practice. The quill editor isn't famous for its security, hence we need to extract the html in order to sanitize it. As long as the user has 100% access to the editor and its code, security is not an argument to me. However, the server should validate every user's input. And that does include the quills content as well. |
If you are trying to bind the content of quill editor to a value, so that it gets loaded on any event you can try this.. |
Hello
I can't seem to find the "setHTML" function.
Here's a screenshot in Chrome. I would have expected it to be displayed next to setText.
Can anyone suggest what I am doing wrong?
thanks
The text was updated successfully, but these errors were encountered: