How to allow removing a single filter indicator when using `indicateUsing`

When working with a custom filter I want to allow removing a single filter option, so I customized the generator indicators using indicateUsing, but when I click the remove button on a single filter all filters are removed. Did I misunderstand the removeField option?
->indicateUsing(function (array $data) {
$indicators = [];

if ($data['rule']) {
Rule::query()->whereIn('id', $data['rule'])->pluck('name', 'id')->each(function ($name) use (&$indicators) {
if (is_string($name)) {
$indicators[] = Indicator::make('Rules: '.$name)->removeField('rule-'.$name);
}
});
}

return $indicators;
})
->indicateUsing(function (array $data) {
$indicators = [];

if ($data['rule']) {
Rule::query()->whereIn('id', $data['rule'])->pluck('name', 'id')->each(function ($name) use (&$indicators) {
if (is_string($name)) {
$indicators[] = Indicator::make('Rules: '.$name)->removeField('rule-'.$name);
}
});
}

return $indicators;
})
4 Replies
Dennis Koch
Dennis Kochβ€’2w ago
Is the rule name alphanumeric without spaces? And your data is keyed by the same name as you pass in removeField()?
Mike πŸš€
Mike πŸš€OPβ€’2w ago
It might contain spaces
Dennis Koch
Dennis Kochβ€’2w ago
Does it also reset all fields? I think ->removeField() is for clearing the fields in the filter form. I guess the indicators are built based on the fields with values, but I am not sure about the inner workings.
Mike πŸš€
Mike πŸš€OPβ€’2w ago
Yeah I think the removeField actually is used for the form if I read the docs more closesely: "f you have different fields associated with different indicators, you should set the field using the removeField() method on the Indicator object to ensure that the correct field is reset when the filter is removed" So I guess it is currently not supported

Did you find this page helpful?