Select component Allow Multiple select
How can I add functionality to a select component so that if the user pastes multiple values, such as "user-1, user-2", both "user-1" and "user-2" get selected?
2 Replies
Select::make()
...
->multiple()
I want to clear the search input and submit the form
@Dennis Koch
->getSearchResultsUsing(static function (
?string $search,
Forms\Components\Select $component,
Forms\Get $get,
) use($supplierId) {
$attribute = $get('attribute');
if ($attribute) {
if (!str_contains($search, ',')) {
return static::filterSearchValues($get, $supplierId, search: $search);
}
$searchArray = array_map('trim', explode(',', $search));
$filters = static::filterSearchValues(
$get,
$supplierId,
array_filter($searchArray, function($value) { return $value !== ''; })
);
$component->state([
...array_keys($filters->toArray()),
...$component->getState(),
]);
return $filters;
}
return [];
})
->getSearchResultsUsing(static function (
?string $search,
Forms\Components\Select $component,
Forms\Get $get,
) use($supplierId) {
$attribute = $get('attribute');
if ($attribute) {
if (!str_contains($search, ',')) {
return static::filterSearchValues($get, $supplierId, search: $search);
}
$searchArray = array_map('trim', explode(',', $search));
$filters = static::filterSearchValues(
$get,
$supplierId,
array_filter($searchArray, function($value) { return $value !== ''; })
);
$component->state([
...array_keys($filters->toArray()),
...$component->getState(),
]);
return $filters;
}
return [];
})