<div style="display: flex; flex-wrap: wrap; white-space: pre-wrap; align-items: center; "><img height="20" width="20" style="border-radius:50%; margin-right: 4px;" decoding="async" src="https://avatars.githubusercontent.com/u/132164321?s=20&v=4" /><strong>prvshkmrin</strong> left a comment <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6599#issuecomment-3638992481">(openstreetmap/openstreetmap-website#6599)</a></div>
<blockquote>
<p dir="auto">Checking for specific key presses can lead to other issues, accessibility being a common example.</p>
<p dir="auto">The issue is with the form submitting at the wrong moment. Therefore it's probably the <em>submission</em> that should be tackled. There's an event for that.</p>
<p dir="auto">I played a bit with this today. I can't tell this is 100% the best option, wondering what others think:</p>
<div class="highlight highlight-source-diff" dir="auto"><pre class="notranslate"><span class="pl-c1">diff --git a/app/assets/javascripts/language_selector.js b/app/assets/javascripts/language_selector.js</span>
index 8380c1b0e..c4bb79821 100644
<span class="pl-md">--- a/app/assets/javascripts/language_selector.js</span>
<span class="pl-mi1">+++ b/app/assets/javascripts/language_selector.js</span>
<span class="pl-mdr">@@ -12,3 +12,7 @@</span> $(document).on("click", "#select_language_dialog [data-language-code]", function
     location.reload();
   }
 });
<span class="pl-mi1"><span class="pl-mi1">+</span></span>
<span class="pl-mi1"><span class="pl-mi1">+</span>$(document).on("submit", "#select_language_form", function (e) {</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>  e.preventDefault();</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>});</span>
<span class="pl-c1">diff --git a/app/views/languages_panes/show.html.erb b/app/views/languages_panes/show.html.erb</span>
index 38a5340f6..82bad7990 100644
<span class="pl-md">--- a/app/views/languages_panes/show.html.erb</span>
<span class="pl-mi1">+++ b/app/views/languages_panes/show.html.erb</span>
<span class="pl-mdr">@@ -1,6 +1,6 @@</span>
 <%= turbo_frame_tag "select_language_list" do %>
   <% if current_user&.id %>
<span class="pl-md"><span class="pl-md">-</span>    <%= form_tag basic_preferences_path, :method => "PUT" do %></span>
<span class="pl-mi1"><span class="pl-mi1">+</span>    <%= form_tag basic_preferences_path, :method => "PUT", :id => "select_language_form", "data-turbo" => false do %></span>
       <%= hidden_field_tag "referer", @source_page %>
       <%= hidden_field_tag "language", I18n.locale %>
       <%= render "select_language_list" %></pre></div>
</blockquote>
<p dir="auto">Yeah, this makes sense — handling the submit event directly is way cleaner than messing around with key checks, and it avoids the accessibility headaches.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6599#issuecomment-3638992481">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLNEEEEKRCYZPJQKJKL4BCESZAVCNFSM6AAAAACONBGL3SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMMZYHE4TENBYGE">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLJ6DSIEHZWBLT6L4R34BCESZA5CNFSM6AAAAACONBGL3SWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTWY42PGC.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/6599/c3638992481</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>

<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/6599#issuecomment-3638992481",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/6599#issuecomment-3638992481",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>