vueup / vue-quill

Rich Text Editor Component for Vue 3.
https://vueup.github.io/vue-quill/
MIT License
1.09k stars 264 forks source link

V-model not work when content is setted to empty #484

Closed overbost closed 3 months ago

overbost commented 8 months ago

Version @vueup/vue-quill 1.2.0

Describe the bug When content is empty string, the quill content is not updated. The content is on the previous state I must use this.$refs.quillEdtor.setHTML("")

To Reproduce Steps to reproduce the behavior:

<QuillEditor
 data-cy="textarea-full-desc"
 ref="quillEditor
 v-model:content="translation.full_desc"
 :placeholder="t('NO_FULL_DESC')"
 contentType="html"
 >
DevTools
content:""
contentType:"html"
enable:true
globalOptions:Object
modules:Object
theme:"snow"
modules:undefined
options:undefined
placeholder:"Aggiungi una descrizione dettagliata"
readOnly:false
theme:"snow"
toolbar:undefined

Expected behavior The content should setted to empty

Additional context I think there is a bug on the code

Penggeor commented 8 months ago

@axolo Worth to fix:

 watch(
      () => props.content,
      (newContent) => {
        if (!quill || !newContent || internalModelEquals(newContent)) return 👈👈👈👈👈

        // Restore the selection and cursor position after updating the content
        const selection = quill.getSelection()
        if (selection) {
          nextTick(() => quill?.setSelection(selection))
        }
        setContents(newContent)
      },
      { deep: true }
    )
Xeyos88 commented 6 months ago

This problem makes it impossible to use it within a form. It is not possible to check whether the content is empty

maksimzinchuk commented 5 months ago

try this to check if content is empty function isEmpty(value: string) { return value.replace(/<(.|\n)*?>/g, "").trim().length === 0; }

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.