Use nuQuillSetContents(). It overwrites the quill editor with given contents. Contents should end with a newline.
Code: Select all
function nuQuillGetInstance(i) {
var container = document.querySelector('#'+ i + '_container');
var quill = new Quill(container);
if (Quill.find(container) === quill) {
return quill;
} else {
return null;
}
}
function nuQuillSetContents(i, contents) {
var quill = nuQuillGetInstance(i);
if (quill !== null) {
if ($.isArray(contents)) {
quill.setContents(contents);
} else {
quill.clipboard.dangerouslyPasteHTML(contents);
}
}
}
Example 1: Pass an array:
(Replace not_content with the ID of your Textarea)
Code: Select all
var contents =
[
{ insert: 'Hello', attributes: { bold: true } },
{ insert: '\n', attributes: { align: 'center' } },
{ insert: 'nuBuilder', attributes: { italic: true }},
{ insert: '\n', attributes: { align: 'center' } }
]
nuQuillSetContents('not_content', contents);
Example 2: Pass some HTML:
Code: Select all
nuQuillSetContents('not_content', '<b>Hello<b><br><i>nuBuilder</i><br>');