Y
Y
Yarik2020-05-04 12:43:38
JavaScript
Yarik, 2020-05-04 12:43:38

How to prevent HTML input on pressing ENTER?

When I click on an empty text field -> ENTER, the following markup is inserted , but I need this markup to be absent and generally on pressing ENTER, if the field is empty, then do nothing with it, I tried to do it like this, but still there is a "backlash" carriages
<div><br></div><div><br></div>

$(".msg-block").keyup(function(event) {
    if (event.keyCode === 13 && $('.emoji-wysiwyg-editor').text() === '' ) {
            $('.emoji-wysiwyg-editor').html('')
    }
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Ineshin, 2020-05-04
@IonDen

To prevent the click from working - you need to add a call to `event.preventDefault()`

N
Nadim Zakirov, 2020-05-04
@zkrvndm

In my opinion, it's a bad idea to use blocks for text input. Better use textarea + autosize.
This is a plugin that automatically changes the height of the text field depending on the number of lines:
https://www.jacklmoore.com/autosize

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question