A
A
Andrew2020-07-30 14:38:10
JavaScript
Andrew, 2020-07-30 14:38:10

How to disable enter in textarea?

Hello, you need to do the following: when you press Enter in a textarea, call the handler function, but do not add a line break. I am using Vue.

I've already tried a bunch of options.

// Не работает :(
<template lang="pug">
textarea(
    @keyup.enter="enterHandler"
)
</template>

<script>

export default {
    methods: {
        enterHandler(event) {
            event.preventDefault()

            // other logic
        }
    }
}
</script>


I also tried to filter the string for the presence of '\n', but the method is extremely inefficient - the cursor position is lost, while line breaks are still saved and disappear only after a character is entered.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alex, 2020-07-30
@Kozack

Use input instead of textarea

0
0xD34F, 2020-07-30
@0xD34F

@keydown.enter.prevent=""

V
Vladimir Martyanov, 2015-02-10
@Android97

"12j3h0Fv7k8L85f93u3TT023m8n3" вы УЖЕ пробовали?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question