Customizing options labels in getRecordSelect() with additional information

->headerActions([
AttachAction::make()
->form(fn (AttachAction $action): array => [
$action
->recordSelect(function ($select) {
$select->options(function () use ($select) {
$options = $select->getOptions();
$formattedOptions = [];
foreach ($options as $value => $label) {
$model = Lotto::find($value);
$formattedLabel = 'Test label';
$formattedOptions[$value] = $formattedLabel;
}
return $formattedOptions;
});
return $select;
})
->preloadRecordSelect()
->getRecordSelect()
->label('Lotto botanica'),
Forms\Components\TextInput::make('grammi_utilizzati')
->required()
->numeric()
->minValue(1)
->mask(fn (TextInput\Mask $mask) => $mask
->numeric(),
)
->suffix('g'),
])
])
->headerActions([
AttachAction::make()
->form(fn (AttachAction $action): array => [
$action
->recordSelect(function ($select) {
$select->options(function () use ($select) {
$options = $select->getOptions();
$formattedOptions = [];
foreach ($options as $value => $label) {
$model = Lotto::find($value);
$formattedLabel = 'Test label';
$formattedOptions[$value] = $formattedLabel;
}
return $formattedOptions;
});
return $select;
})
->preloadRecordSelect()
->getRecordSelect()
->label('Lotto botanica'),
Forms\Components\TextInput::make('grammi_utilizzati')
->required()
->numeric()
->minValue(1)
->mask(fn (TextInput\Mask $mask) => $mask
->numeric(),
)
->suffix('g'),
])
])
I was trying to customize the labels of the options with this code, but I'm having trouble. What am I doing wrong? Thank you.
2 Replies
Dan Harrin
Dan Harrin2y ago
you need to use $action->getRecordSelect() in the form. you dont need to override options() you need to use the ->recordTitle(fn ($record) => generate title from record here) on the action level that should be it
steexd
steexdOP2y ago
Thank you! Using
->recordTitle(fn ($record) =>
->recordTitle(fn ($record) =>
did the trick I really appreciate your help!
Want results from more Discord servers?
Add your server