N
N
Nikita Bratsky2021-03-24 00:02:44
JavaScript
Nikita Bratsky, 2021-03-24 00:02:44

How to disable the ability to send empty messages on pressing enter?

window.addEventListener ("keypress", function (e) {
      if (e.keyCode === 13 && input.value != ''){
              event.preventDefault();
              socket.emit('событие', input.value);
       	      input.value = '';
              return false;
     }
});

Here is my code, I can't cancel the transfer to the next line because of which it is sent by pressing enter. The first message is not sent, and then the transfer occurs and after that the message is sent, how to solve this problem? I would also like to add the ability to wrap to the next line via shift + enter

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
v3shin, 2021-03-24
@NikBr_9

input.value.trim()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question