Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Hide search filters if the search yields no result.
*/
(function (Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.hideFilters = {
attach: function (context, settings) {
let noResult = document.getElementById('js-no-result');
if (noResult) {
document.getElementById('js-search-filters').style.display = 'none';
}
}
};

})(Drupal, drupalSettings);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hide-filters:
version: 1.x
js:
assets/js/hideFilters.js: {}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public function getContentTypeGroups(): array {
public function formAlter(array &$form, FormStateInterface $form_state, $form_id) {
if ('views_exposed_form' === $form_id
&& 'views-exposed-form-os2loop-search-db-page-search' === ($form['#id'] ?? NULL)) {
$form['#attached']['library'][] = 'os2loop_search_db/hide-filters';
// Add facet filter query to form to keep the filters when submitting
// search form.
$request = $this->requestStack->getCurrentRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
*/
#}
{# @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Search_role#examples #}
<form{{ attributes.setAttribute('role', 'search') }} class="form" >
<form{{ attributes.setAttribute('role', 'search') }} class="form">
<div class="row">
{{ children }}
</div>
<div class="col-12">
<div class="col-12" id="js-search-filters">
<div class="row">
<div class="col ml-2 border-bottom">
<h6 class="d-inline align-middle p-0">{{ 'Search filters'|t }}</h6>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set os2loop_settings = get_os2loop_config('os2loop_settings.settings') %}

<div class="col-12">
<div class="col-12" id="js-no-result">
<div class="mb-4">
<h2 class="h5">{{ 'Unfortunately your search yielded no result.'|t }}</h2>
<div class="d-block">{{ 'Check that you have spelled correctly or try another search term.'|t }}</div>
Expand Down