[openstreetmap/openstreetmap-website] Fix: prevent form submission breaking language selector (#6598) (PR #6599)
Parvesh Kumar
notifications at github.com
Wed Dec 10 21:16:28 UTC 2025
prvshkmrin left a comment (openstreetmap/openstreetmap-website#6599)
> Checking for specific key presses can lead to other issues, accessibility being a common example.
>
> The issue is with the form submitting at the wrong moment. Therefore it's probably the _submission_ that should be tackled. There's an event for that.
>
> I played a bit with this today. I can't tell this is 100% the best option, wondering what others think:
>
> ```diff
> diff --git a/app/assets/javascripts/language_selector.js b/app/assets/javascripts/language_selector.js
> index 8380c1b0e..c4bb79821 100644
> --- a/app/assets/javascripts/language_selector.js
> +++ b/app/assets/javascripts/language_selector.js
> @@ -12,3 +12,7 @@ $(document).on("click", "#select_language_dialog [data-language-code]", function
> location.reload();
> }
> });
> +
> +$(document).on("submit", "#select_language_form", function (e) {
> + e.preventDefault();
> +});
> diff --git a/app/views/languages_panes/show.html.erb b/app/views/languages_panes/show.html.erb
> index 38a5340f6..82bad7990 100644
> --- a/app/views/languages_panes/show.html.erb
> +++ b/app/views/languages_panes/show.html.erb
> @@ -1,6 +1,6 @@
> <%= turbo_frame_tag "select_language_list" do %>
> <% if current_user&.id %>
> - <%= form_tag basic_preferences_path, :method => "PUT" do %>
> + <%= form_tag basic_preferences_path, :method => "PUT", :id => "select_language_form", "data-turbo" => false do %>
> <%= hidden_field_tag "referer", @source_page %>
> <%= hidden_field_tag "language", I18n.locale %>
> <%= render "select_language_list" %>
> ```
Yeah, this makes sense — handling the submit event directly is way cleaner than messing around with key checks, and it avoids the accessibility headaches.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6599#issuecomment-3638992481
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/6599/c3638992481 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20251210/9fd3887b/attachment.htm>
More information about the rails-dev
mailing list