Skip to content

Commit

Permalink
Change global search from POST to GET to allow better back-button beh…
Browse files Browse the repository at this point in the history
…avior (CFM-323) (#126)
  • Loading branch information
arlen authored Sep 21, 2023
1 parent 67fd942 commit 1af88ab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
13 changes: 4 additions & 9 deletions app/src/Controller/DashboardsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,9 @@ public function search() {

// Gather our search string.
$q = '';
if(!empty($this->request->getData('global-search-q'))) {
// A search was passed in from the global search-bar.
$q = trim($this->request->getData('global-search-q'));
// Now pass the search string to the in-page search form and empty the global search bar.
$this->setRequest($this->getRequest()->withData('global-search-q', '')->withData('q', $q));
} elseif(!empty($this->request->getData('q'))) {
// A search was passed in from the form on the Global Search page.
$q = trim($this->request->getData('q'));
if(!empty($this->request->getQuery('q'))) {
// A search was passed in from the form on the Global Search bar.
$q = trim($this->request->getQuery('q'));
}

// Only process the request if we have a string of non-space characters
Expand Down Expand Up @@ -403,7 +398,7 @@ public function search() {

$this->Flash->information(__d('result',
'search.exact',
[filter_var($this->request->getData('q'), FILTER_SANITIZE_SPECIAL_CHARS),
[filter_var($this->request->getQuery('q'), FILTER_SANITIZE_SPECIAL_CHARS),
__d('controller', $matchClass, [1])]));

// Redirect to the matchClass controller
Expand Down
6 changes: 3 additions & 3 deletions app/templates/element/javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
$('#global-search-clear').click(function(e) {
e.stopPropagation();
$('#q').val('');
$('#q').removeClass('hasValue');
$('#q').removeClass('has-value');
$('#q').focus();
});
// Select search text on focus
Expand All @@ -83,9 +83,9 @@
// Hide and reveal clear button
$('#q').on('input', function(e) {
if($(this).val() != '') {
$(this).addClass('hasValue');
$(this).addClass('has-value');
} else {
$(this).removeClass('hasValue');
$(this).removeClass('has-value');
}
});

Expand Down
11 changes: 6 additions & 5 deletions app/templates/element/searchGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

$options = [
'type' => 'post',
'type' => 'get',
'url' => [
'plugin' => null,
'controller' => 'dashboards',
Expand All @@ -51,16 +51,17 @@
__d('field','search.global'),
['class' => 'visually-hidden']
);
$globalSearchInputClass = '';
if(!empty($this->request->getData('q'))) {
$globalSearchInputClass = 'hasValue';
$globalSearchInputClass = 'global-search-query';
if(!empty($this->request->getQuery('q'))) {
$globalSearchInputClass .= ' has-value';
}
print $this->Form->input(
'q',
[
'id' => 'q',
'class' => $globalSearchInputClass,
'placeholder' => __d('field','search.placeholder')
'placeholder' => __d('field','search.placeholder'),
'value' => $this->request->getQuery('q')
]
);
print $this->Form->button(
Expand Down
2 changes: 1 addition & 1 deletion app/webroot/css/co-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ body.cos.select #top-bar {
color: var(--cmg-color-txt-inverse);
border-right: 1px dotted var(--cmg-color-highlight-005);
}
#q.hasValue + #global-search-clear {
#q.has-value + #global-search-clear {
display: inline-block;
}
#top-bar #global-search-toggle {
Expand Down

0 comments on commit 1af88ab

Please sign in to comment.