event.preventDefault() can't work well
See original GitHub issueI 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@feedgit
@keydown.enter.native.capture.prevent="update"
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.No.