Skip to content

Commit

Permalink
Merge pull request #802 from City-of-Helsinki/UHF-11045
Browse files Browse the repository at this point in the history
UHF-11045: Fix autocomplete route
  • Loading branch information
jeremysteerio authored Dec 17, 2024
2 parents bd298d2 + 87738bf commit 496d288
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions public/modules/custom/helfi_etusivu/src/Form/NearYouForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
* Search form for near you page.
Expand All @@ -30,6 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#attached' => [
'drupalSettings' => [
'helsinki_near_you_form' => [
'autocompleteRoute' => Url::fromRoute('helfi_etusivu.helsinki_near_you_autocomplete')->tosTring(),
'minCharAssistiveHint' => $this->t('Type @count or more characters for results', [], ['context' => $translation_context]),
'inputAssistiveHint' => $this->t(
'When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.',
Expand All @@ -51,6 +53,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#placeholder' => $this->t('Eg. Vaasankatu 5', [], ['context' => 'Helsinki near you']),
'#required' => TRUE,
'#title' => $this->t('Address'),
'#label_attributes' => [
'class' => [
'hds-text-input__label',
],
],
'#type' => 'helfi_etusivu_autocomplete',
'#wrapper_attributes' => [
'class' => [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ a11y_autocomplete:
helfi_etusivu_autocomplete:
js:
dist/js/autocomplete.min.js: {}
version: 1.0.0
version: 1.0.1
dependencies:
- hdbt_subtheme/a11y_autocomplete
- core/drupal
Expand Down
3 changes: 2 additions & 1 deletion public/themes/custom/hdbt_subtheme/src/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}

const {
autocompleteRoute,
noResultsAssistiveHint,
someResultsAssistiveHint,
oneResultAssistiveHint,
Expand All @@ -39,7 +40,7 @@
}

try {
const response = await fetch(`/helsinki-near-you/results/autocomplete?q=${searchTerm}`, {});
const response = await fetch(`${autocompleteRoute}?q=${searchTerm}`, {});
const data = await response.json();
results(data);
}
Expand Down

0 comments on commit 496d288

Please sign in to comment.