From e7f3a466e4ccc6f8a718d4e3d9802d106576dc9a Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 24 May 2016 18:32:16 +0530 Subject: [PATCH 1/2] Allow configuring default use of selectize and autocomplete. --- src/Listener/ViewSearchListener.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index 87694e80..66cb5ecd 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -15,7 +15,9 @@ class ViewSearchListener extends BaseListener * @var array */ protected $_defaultConfig = [ - 'enabled' => null + 'enabled' => null, + 'autocomplete' => true, + 'selectize' => true, ]; /** @@ -79,6 +81,7 @@ protected function _deriveFields() $fields = []; $schema = $table->schema(); + $config = $this->_config; foreach ($filters->all() as $filter) { if ($filter->config('form') === false) { @@ -99,10 +102,7 @@ protected function _deriveFields() 'type' => 'text' ]; - $value = $request->query($field); - if ($value !== null) { - $input['value'] = $value; - } + $input['value'] = $request->query($field); if (empty($input['options']) && $schema->columnType($field) === 'boolean') { $input['options'] = ['No', 'Yes']; @@ -111,11 +111,16 @@ protected function _deriveFields() if (!empty($input['options'])) { $input['empty'] = true; + if (empty($input['class']) && !$config['selectize']) { + $input['class'] = 'no-selectize'; + } + $fields[$field] = $input; + continue; } - if (empty($input['class'])) { + if (empty($input['class']) && $config['autocomplete']) { $input['class'] = 'autocomplete'; } From ce492f0165cd12a8a075ce1163420d69e9928b72 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 25 May 2016 13:17:36 +0530 Subject: [PATCH 2/2] Skip event handling if is Search behavior is not loaded. --- src/Listener/ViewSearchListener.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index 66cb5ecd..02747cb1 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -43,6 +43,10 @@ public function implementedEvents() */ public function afterPaginate(Event $event) { + if (!$this->_table()->behaviors()->has('Search')) { + return; + } + $enabled = $this->config('enabled') ?: !$this->_request()->is('api'); if (!$enabled) { return;