Skip to content

Commit

Permalink
refactor: don't use anchor link in form action (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen authored May 7, 2024
1 parent 91c70fc commit fd9adcd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ Hooks.AlgoliaAutocomplete = {
setupAlgoliaAutocomplete(this.el);
}
};
Hooks.ScrollIntoView = {
// FIXME: This shouldn't need a hook; it could be implemented with
// `phx-mounted={JS.dispatch("scrollIntoView", to: #element)}` and a window
// event listener.
mounted() {
this.el.scrollIntoView({ behavior: "smooth" });
}
};
let liveSocket = new LiveSocket("/live", Socket, {
params: { _csrf_token: csrfToken },
hooks: Hooks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<%= if assigns[:text] do %>
<p><%= @text %></p>
<% end %>
<%= form_for @conn, "/trip-planner"<>"#plan_result_focus", form_options, fn _ -> %>
<%= form_for @conn, "/trip-planner", form_options, fn _ -> %>
<%= DotcomWeb.TripPlanView.render("_to_from_inputs.html", Map.merge(assigns, %{ from_error: from_error, to_error: to_error, from_position: from_position, to_position: to_position })) %>
<%= DotcomWeb.TripPlanView.render("_submit_button.html", assigns) %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom_web/templates/trip_plan/_sidebar.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<%= render "_error.html", plan_error: plan_error %>
<div class="m-trip-plan__form-container callout">
<%= render "_mobile_trip_summary.html", query: query, itineraries?: itineraries? %>
<%= form_for @conn, @conn.request_path<>"#plan_result_focus", form_options, fn f -> %>
<%= form_for @conn, @conn.request_path, form_options, fn f -> %>
<%= render "_to_from_inputs.html", Map.merge(assigns, to_from_assigns) %>
<%= render "_options.html", conn: @conn, parent_form: f, errors: plan_error, query: query, modes: @modes, wheelchair: @wheelchair, plan_datetime_selector_fields: @plan_datetime_selector_fields %>
<%= render "_submit_button.html" %>
Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom_web/templates/trip_plan/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="stylesheet" href="<%= static_url(@conn, "/css/map.css") %>">
<%= case assigns[:query] do %>
<% %{itineraries: {:ok, _}} -> %>
<p class="no-trips page-section">
<p class="no-trips page-section" autofocus phx-hook="ScrollIntoView">
<% l = length(@itineraries) %>
<%= "We found #{l} #{Inflex.inflect("trip", l)} for you" %>
</p>
Expand Down

0 comments on commit fd9adcd

Please sign in to comment.