Skip to content

Commit

Permalink
Merge pull request #151 from Nikorag/bugfix/81
Browse files Browse the repository at this point in the history
Fix chat in firefox. submit form is deprecated

Thanks for the investigation why Firefox did not handle eventlisteners on form-elements.
Did not know that.
  • Loading branch information
clusterzx authored Jan 14, 2025
2 parents 7eb4989 + 999d756 commit cb2ae1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions public/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,14 @@ document.getElementById('documentSelect').addEventListener('change', function()
}
});

document.getElementById('messageForm').addEventListener('submit', async function(e) {
e.preventDefault();

document.getElementById('messageInput').addEventListener('keydown', async (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
await submitForm();
}
})

async function submitForm(){
const messageInput = document.getElementById('messageInput');
const message = messageInput.value.trim();

Expand All @@ -214,7 +219,7 @@ document.getElementById('messageForm').addEventListener('submit', async function
if (response) {
addMessage(response, false);
}
} catch (error) {
} catch {
showError('Failed to send message');
}
});
}
4 changes: 2 additions & 2 deletions views/chat.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>

<!-- Message Input -->
<form id="messageForm" class="message-form hidden">
<div id="messageForm" class="message-form hidden">
<input type="hidden" id="documentId" name="documentId" value="">
<textarea
id="messageInput"
Expand All @@ -51,7 +51,7 @@
<button type="submit" class="send-button">
Send
</button>
</form>
</div>
</div>
</div>

Expand Down

0 comments on commit cb2ae1b

Please sign in to comment.