如何使 quill 编辑器成为必需? [英] How to make quill editor required?
问题描述
如何使 quill 编辑器字段成为必需?编辑器被渲染成一个 div,但不清楚是否有办法在表单提交时使字段/编辑器成为必需的.
How to make the quill editor field required? The editor gets rendered into a div, but it isn't clear if there is a way to make the field/editor required when the form submits.
推荐答案
如您所写,Quill 使用 div 而不是表单元素,因此无法帮助您进行表单验证.您需要手动检查编辑器的内容是否为空,阻止用户提交表单并显示一条消息,表明该字段是必需的.
As you wrote, Quill works with a div and not with a form element so it can't help you with form validation. You'll need to check manually if the editor's content is empty, prevent the user from submitting the form and show a message that this field is required.
您可以在提交表单之前将 quill 内容复制到隐藏的输入元素,如本示例.
You can copy quill contents to a hidden input element before submitting the form as shown in this example.
这篇关于如何使 quill 编辑器成为必需?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!