No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    q-editor no blur ?

    Framework
    4
    7
    1353
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tntneo last edited by

      Hi All. Is it correct to say that q-editor has no blur event?

      I would love to use the same process I use with other input fields (blur event).
      Is there any way with q-editor to know when editing stopped?
      (by the way, would be also a great event for the other input components).

      I know v-model is synced automatically. My issue is to be able to detect when modifications are done… or at least stopped for a few seconds.

      Maybe you know another way I did not think of (with v-model maybe)…
      Anyone?

      1 Reply Last reply Reply Quote 0
      • G
        genyded last edited by

        Well… first off, q-editor is NOT an input element, it’s a contenteditable div element (like just about any other WYSIWYG editor out there). As such there is no blur event. It’s depends on what you want to do when “modifications are done” what (if anything) may work to meet those needs. Sometimes having the editor in a dialog with a save button will work. You could out it inside a card with action buttons that show up when changes are made. There may be some things you can do with custom directives, but again, it depends on what exactly you need. There are also some hacks with focusout events for some scenarios, but browser support varies and I would only recommend that as a last resort.

        So, unless the html spec changes, a blur event is not an option. Given that, it really depends on what your needs are.

        1 Reply Last reply Reply Quote 0
        • T
          tntneo last edited by

          Thank you for your help. Now I understand the discrepancy.
          I was trying to do something too complicated anyway.
          The Save button is the simple solution.

          1 Reply Last reply Reply Quote 0
          • A
            Ado20 last edited by

            You can easily accomplish blur on q-editor like this:

            1.) Create reference:

            <q-editor ref=“q-editor” …

            2.) Add event listener in Vue ‘created’ hook:

            created () {
            this.$nextTick(() => {
            const contenteditable = this.$refs[‘q-editor’].$el.querySelector(’[contenteditable]’)
            contenteditable.addEventListener(‘blur’, () => {
            // do what you want
            })
            })
            }

            1 Reply Last reply Reply Quote 2
            • T
              tntneo last edited by

              very interesting!
              learn something everyday.
              Thanks

              1 Reply Last reply Reply Quote 0
              • G
                genyded last edited by

                Be careful trying to extend it though and if you do test it well. Browser support for ContentEditable is widely varies and likely part of the reason it does not have a native blur event to begin with.In theory it should work, but your mileage may vary.

                1 Reply Last reply Reply Quote 1
                • Merrick
                  Merrick last edited by Merrick

                  @Ado20 is using something like you have above suitable for accessing q-editor state?

                  My goal is to clone state from this.$refs['q-editor'].caret to the parent component. I have something like above working though I’m running into issues using the regular Vue lifecycle hooks as my q-editor is conditionally displayed (so this.$refs['q-editor'].caret is undefined for created/mounted).

                  Generally speaking, what’s the best practice for accessing a built-in child component’s state?

                  Edit: Maybe I was over thinking it using a listener, ended up using the following:

                      injectContent () {
                        if (this.$refs['q-editor'] && this.$refs['q-editor'].caret) {
                          this.caretRange = this.$refs['q-editor'].caret.range
                        }
                        // insert content at caret position
                      },
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post