From b7202eea046f7c62ad07fb96a0e0bdfd5a42b575 Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Wed, 27 Sep 2023 12:37:18 -0400 Subject: [PATCH] Revert "Change global search from POST to GET to allow better back-button behavior (CFM-323) (#126)" This reverts commit 1af88abc2f26bd817d707ce2a17c079580c3d9c5. --- app/src/Controller/DashboardsController.php | 13 +++++++++---- app/templates/element/javascript.php | 6 +++--- app/templates/element/searchGlobal.php | 11 +++++------ app/webroot/css/co-base.css | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/Controller/DashboardsController.php b/app/src/Controller/DashboardsController.php index 0e5ffb211..12562df3d 100644 --- a/app/src/Controller/DashboardsController.php +++ b/app/src/Controller/DashboardsController.php @@ -311,9 +311,14 @@ public function search() { // Gather our search string. $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')); + 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')); } // Only process the request if we have a string of non-space characters @@ -398,7 +403,7 @@ public function search() { $this->Flash->information(__d('result', 'search.exact', - [filter_var($this->request->getQuery('q'), FILTER_SANITIZE_SPECIAL_CHARS), + [filter_var($this->request->getData('q'), FILTER_SANITIZE_SPECIAL_CHARS), __d('controller', $matchClass, [1])])); // Redirect to the matchClass controller diff --git a/app/templates/element/javascript.php b/app/templates/element/javascript.php index 38efe508e..e66ed5a03 100644 --- a/app/templates/element/javascript.php +++ b/app/templates/element/javascript.php @@ -73,7 +73,7 @@ $('#global-search-clear').click(function(e) { e.stopPropagation(); $('#q').val(''); - $('#q').removeClass('has-value'); + $('#q').removeClass('hasValue'); $('#q').focus(); }); // Select search text on focus @@ -83,9 +83,9 @@ // Hide and reveal clear button $('#q').on('input', function(e) { if($(this).val() != '') { - $(this).addClass('has-value'); + $(this).addClass('hasValue'); } else { - $(this).removeClass('has-value'); + $(this).removeClass('hasValue'); } }); diff --git a/app/templates/element/searchGlobal.php b/app/templates/element/searchGlobal.php index 3282f4e36..faf8a3d17 100644 --- a/app/templates/element/searchGlobal.php +++ b/app/templates/element/searchGlobal.php @@ -26,7 +26,7 @@ */ $options = [ - 'type' => 'get', + 'type' => 'post', 'url' => [ 'plugin' => null, 'controller' => 'dashboards', @@ -51,17 +51,16 @@ __d('field','search.global'), ['class' => 'visually-hidden'] ); - $globalSearchInputClass = 'global-search-query'; - if(!empty($this->request->getQuery('q'))) { - $globalSearchInputClass .= ' has-value'; + $globalSearchInputClass = ''; + if(!empty($this->request->getData('q'))) { + $globalSearchInputClass = 'hasValue'; } print $this->Form->input( 'q', [ 'id' => 'q', 'class' => $globalSearchInputClass, - 'placeholder' => __d('field','search.placeholder'), - 'value' => $this->request->getQuery('q') + 'placeholder' => __d('field','search.placeholder') ] ); print $this->Form->button( diff --git a/app/webroot/css/co-base.css b/app/webroot/css/co-base.css index 331af0b29..7bf3c5953 100644 --- a/app/webroot/css/co-base.css +++ b/app/webroot/css/co-base.css @@ -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.has-value + #global-search-clear { +#q.hasValue + #global-search-clear { display: inline-block; } #top-bar #global-search-toggle {