Reputation: 1
I'm having an issue with my chat bot app where a line break is being inserted into the form after the user is pressing the submit button. To clarify, the message is being sent, but then creating a line break so the user has to backspace for the form to be completely empty.
var enableEnterKey = function() {
$(document).keypress(function(e) {
if($('#maxx-message-box').is(':focus') && e.keyCode === 13) {
var message = $('#maxx-message-box').val();
sendMessage(message);
}
});
This is our function. Please help.
Upvotes: 0
Views: 39
Reputation: 5719
You probably need something like:
$("#maxx-message-box").keypress(function (e) {
if (e.keyCode != 13) return;
var message = $("#maxx-message-box").val().replace(/\n/g, "");
if (!!message)
{
sendMessage(message);
$("#maxx-message-box").val("");
}
return false;
});
Upvotes: 0