Skip to content

Commit

Permalink
Merge pull request #127 from FriendsOfCake/viewsearchlistener-config
Browse files Browse the repository at this point in the history
Allow configuring default use of selectize and autocomplete.
  • Loading branch information
jippi committed Jun 2, 2016
2 parents 1999f15 + ce492f0 commit 0794fa1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Listener/ViewSearchListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class ViewSearchListener extends BaseListener
* @var array
*/
protected $_defaultConfig = [
'enabled' => null
'enabled' => null,
'autocomplete' => true,
'selectize' => true,
];

/**
Expand All @@ -41,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;
Expand Down Expand Up @@ -79,6 +85,7 @@ protected function _deriveFields()

$fields = [];
$schema = $table->schema();
$config = $this->_config;

foreach ($filters->all() as $filter) {
if ($filter->config('form') === false) {
Expand All @@ -99,10 +106,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'];
Expand All @@ -111,11 +115,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';
}

Expand Down

0 comments on commit 0794fa1

Please sign in to comment.