我有以下代码,尝试创建Quill元素,插入文本,然后在发送表单时,Quill元素将新文本发送到db,仅适用于第一个和最后一个Quill元素,有什么想法吗?
表格
%input.description{type:"hidden", name:"descriptions[]", value:"#{lesson.description}", id:"#{lesson_id}"}
.quill{id:"#{lesson_id}"}
.ui.hidden.divider
:javascript
$(document).ready(function(){
createQuill($("##{lesson_id}.quill")[0], #{lesson.description.html_safe})
})
JS函数
function createQuill(editor, content=null){
id = $(editor).attr('id')
this.description = $("#"+ id +".description")
this.quill = new Quill(editor, {
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['clean'], // remove formatting button
['link', 'formula', 'image', 'video'] // formula, image and video implement
]
},
placeholder: 'Escribe una descripción...',
theme: 'snow'
});
this.quill.setContents(content).innerHTML
document.getElementById('submit').addEventListener('click', function(event){
event.preventDefault();
console.log(description)
// Populate hidden form on submit
description[0].value = JSON.stringify(quill.getContents())
}.bind(this), false)
}