F
Filament13mo ago
Bartek

Is there a way to modify option label strings in default AttachAction class?

I'm having issues attempting to modify option labels in Attach Action dropdown. What I want to do is to prefix them with string. Tried various approaches from the docs but it seems they are being overwritten? I know you can customise record title by setting recordTitleAttribute() method but that only allows us to choose different attribute on the model. I cannot modify the model or migration. I need a way to mutate options labels as the dropdown is populated. Any help will be appreciated.
Solution:
Turns out we can mutate options array that is generated by AttachAction by using recordSelect method like this: ```php AttachAction::make() ->preloadRecordSelect()...
Jump to solution
1 Reply
Solution
Bartek
Bartek13mo ago
Turns out we can mutate options array that is generated by AttachAction by using recordSelect method like this:
AttachAction::make()
->preloadRecordSelect()
->recordSelect(function (Select $select) {
$prefix = 'Prefix';

$result = [];
foreach ($select->getOptions() as $key => $value) {
$result[$key] = $prefix . ' - ' . $value;
}

return $select->options($result);
}),
AttachAction::make()
->preloadRecordSelect()
->recordSelect(function (Select $select) {
$prefix = 'Prefix';

$result = [];
foreach ($select->getOptions() as $key => $value) {
$result[$key] = $prefix . ' - ' . $value;
}

return $select->options($result);
}),
Want results from more Discord servers?
Add your server