Skip to content

Commit

Permalink
Rewrote attributes handling in Filters; Closes #434
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed Jan 6, 2017
1 parent ea9fadf commit 857ef7e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
30 changes: 26 additions & 4 deletions src/Filter/Filter.php
Expand Up @@ -71,7 +71,7 @@ abstract class Filter extends Nette\Object
* @var array
*/
protected $attributes = [
['class', 'form-control input-sm']
'class' => ['form-control', 'input-sm'],
];


Expand Down Expand Up @@ -255,7 +255,20 @@ public function getType()
*/
public function addAttribute($name, $value)
{
$this->attributes[] = [(string) $name, $value];
$this->attributes[$name][] = $value;

return $this;
}


/**
* @param string $name
* @param mixed $value
* @return static
*/
public function setAttribute($name, $value)
{
$this->attributes[$name] = (array) $value;

return $this;
}
Expand All @@ -271,6 +284,10 @@ public function getAttribtues()
return $this->getAttributes();
}


/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
Expand All @@ -289,8 +306,13 @@ protected function addAttributes($input)
$input->setAttribute('data-datagrid-manualsubmit', TRUE);
}

foreach ($this->attributes as $attribute) {
$input->setAttribute($attribute[0], $attribute[1]);
foreach ($this->attributes as $key => $value) {
if (is_array($value)) {
$value = array_unique($value);
$value = implode(' ', $value);
}

$input->setAttribute($key, $value);
}

return $input;
Expand Down
7 changes: 0 additions & 7 deletions src/Filter/FilterDate.php
Expand Up @@ -28,13 +28,6 @@ class FilterDate extends Filter implements IFilterDate
*/
protected $type = 'date';

/**
* @var array
*/
protected $attributes = [
['class', 'form-control input-sm']
];


/**
* Adds select box to filter form
Expand Down
7 changes: 0 additions & 7 deletions src/Filter/FilterDateRange.php
Expand Up @@ -28,13 +28,6 @@ class FilterDateRange extends FilterRange implements IFilterDate
*/
protected $type = 'date-range';

/**
* @var array
*/
protected $attributes = [
['class', 'form-control input-sm']
];


/**
* Adds select box to filter form
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/FilterMultiSelect.php
Expand Up @@ -23,8 +23,8 @@ class FilterMultiSelect extends FilterSelect
* @var array
*/
protected $attributes = [
['class', 'form-control selectpicker input-sm'],
['data-selected-text-format', 'count']
'class' => ['form-control', 'input-sm', 'selectpicker'],
'data-selected-text-format' => ['count'],
];


Expand Down

0 comments on commit 857ef7e

Please sign in to comment.