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
tesse05
tesse056mo ago
Select::make() ... ->multiple()
Umar Farooq
Umar FarooqOP6mo ago
I want to clear the search input and submit the form
->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 [];
})
@Dennis Koch
Want results from more Discord servers?
Add your server