Skip to content

Commit

Permalink
Fix filter number not clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
dansysanalyst committed May 25, 2024
1 parent 7b187b8 commit ca1cbd9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Concerns/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public function clearFilter(string $field = '', bool $emit = true): void
{
collect($this->filters())
->each(function ($filter) use ($field) {
/**
* Filter Number will generate FIELD_start and FIELD_end fields,
* and both fields should also be cleaned.
* Here we verify if there are filter numbers and their fields.
*/

$extraFieldsToClear = [];

if (!empty($this->filters['number'])) {
$numberField = str($field)->beforeLast('_start')->beforeLast('_end')->append('')->toString();

if (isset($this->filters['number'][$numberField])) {
$field = $numberField;
$extraFieldsToClear = [$numberField . '_start', $numberField . '_end'];
}
}

if (isset($this->filters['multi_select'][$field])) {
$this->dispatch('pg:clear_multi_select::' . $this->tableName . ':' . $field);
}
Expand Down Expand Up @@ -55,6 +72,10 @@ public function clearFilter(string $field = '', bool $emit = true): void

if ($field === data_get($filter, 'field')) {
$unset($filter, $field, null);

foreach ($extraFieldsToClear as $fieldToClear) {
$unset($filter, $fieldToClear, null);
}
};
});

Expand Down

0 comments on commit ca1cbd9

Please sign in to comment.