question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

event.preventDefault() can't work well

See original GitHub issue

I have a component for Comments like this:

<template>
  <section class="cmt">
        <div class="quill-editor" @keydown.enter="update" v-model="content" v-quill:myQuillEditor="editorOption"></div>
        <div class="html ql-editor" v-html="content"></div>
  </section>
</template>

<script>
export default {
  data: function () {
    return {
      content: '',
      editorOption: {
        modules: {
          toolbar: false
        },
        placeholder: 'Write a comment...'
      }
    }
  },
  methods: {
    update: function (editor) {
      if (editor.keyCode === 13 && !editor.shiftKey && this.content.length > 0) {
        alert(this.content)
        console.log(this.content)
        editor.preventDefault()
      }
    }
  }
}
</script>

Now I pressing enter example: Test. It will be generated HTML: <p>Test</p><p><br></p>. This must be: <p>Test</p>. I use preventDefault() but itn’t work. How can I fix this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
surmon-chinacommented, Nov 7, 2017

@feedgit

  1. @keydown.enter.native.capture.prevent="update"

  2. If you just want to block the enter event, then you can block key events by registering a quill module or intercepting events via vue listeners. Also <p> <br> </ p> is inevitable and quill relies on this work.

0reactions
surmon-chinacommented, Nov 9, 2017

No.

Read more comments on GitHub >

github_iconTop Results From Across the Web

preventDefault() doesn't prevent the action - Stack Overflow
You want event.stopImmediatePropagation(); if there are multiple event handlers on an element and you want to prevent the others to execute.
Read more >
How to correctly use preventDefault(), stopPropagation(), or ...
Here we have taken the click event and prevented its default behaviour using event.preventDefault() , then invoked the fileUpload() function ...
Read more >
event.preventDefault() not working when clicks <a> elements
Describe the bug. We want to capture all click events on < a > elements, and then open link in new tauri window...
Read more >
I can't get event.preventDefault(); to work. - Treehouse
I'm trying to get prevent the user from being taken to a dead end when they click on a pick in my image...
Read more >
Events: change, input, cut, copy, paste
So we can't use event.preventDefault() there – it's just too late, there would be no effect. Events: cut, copy, paste. These events ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found