Skip to content

Instantly share code, notes, and snippets.

View Fanoflix's full-sized avatar
🌏
Its hustlin' time

Muhammad Ammar Fanoflix

🌏
Its hustlin' time
View GitHub Profile
@KacperKozak
KacperKozak / ctrl-enter.js
Last active May 4, 2024 12:24
[Ctrl] + [Enter] to submit forms
document.body.addEventListener('keydown', (event) => {
if(event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
event.target.form?.submit();
}
});
@Fanoflix
Fanoflix / ctrl-enter.ts
Last active October 14, 2024 08:10
Ctrl + Enter to submit Form (Typescript)
document.body.addEventListener("keydown", (e: KeyboardEvent) => {
if (!(e.key === "Enter" && (e.metaKey || e.ctrlKey))) return
if ('form' in e.target) {
const formElement = e.target.form as HTMLFormElement;
formElement?.submit(); // or formElement?.requestSubmit() depending on your usecase
}
})