Skip to content

Commit

Permalink
Run search when filters change
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJackson-Oslo committed Sep 20, 2024
1 parent eb4b1ce commit ea4620e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/javascript/controllers/mapbox_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import capsule_html from './search_and_filter/capsule_html';

export default class extends Controller {
static targets = [
"form",
"location",
"northWestLatInput",
"northWestLngInput",
Expand Down Expand Up @@ -262,6 +263,8 @@ export default class extends Controller {
this.southEastLatInputTarget.value = southEastLat;
this.southEastLngInputTarget.value = southEastLng;

this.formTarget.requestSubmit();

this.map.fitBounds(bounds, {
padding: 0,
animate: false
Expand Down
5 changes: 3 additions & 2 deletions app/views/spaces/index/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<%= form_with url: spaces_path, method: :get, data: {
controller: 'sync-fields-with-same-id',
sync_fields_with_same_id_target: 'form'
sync_fields_with_same_id_target: 'form',
mapbox_target: 'form'
} do |form| %>
<%= render 'spaces/index/search_form_fields', form: %>
<%= form.submit "Søk", class: "button submit fixed bottom-4" %>
<%= form.submit "Søk", class: "button submit fixed bottom-4 sr-only" %>
<% end %>
2 changes: 2 additions & 0 deletions app/views/spaces/index/_search_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
multiple: true,
class: "h-5 w-5 text-lnu-pink focus:ring-lnu-pink border-gray-300 rounded",
data: { mapbox_target: "facility" },
onchange: "!this.id.startsWith('duplicate-') && this.form.requestSubmit()",
checked: params[:facilities]&.include?(facility.id.to_s)
},
facility.id.to_s,
Expand All @@ -72,6 +73,7 @@
id: "space_type_#{space_type.id}",
data: { mapbox_target: "spaceType" },
class: "h-5 w-5 text-lnu-pink focus:ring-lnu-pink border-gray-300 rounded",
onchange: "!this.id.startsWith('duplicate-') && this.form.requestSubmit()",
checked: params[:space_types]&.include?(space_type.id.to_s)

},
Expand Down

0 comments on commit ea4620e

Please sign in to comment.