Form select not updating options data

so i was creating color from inside a Select components using createOptionForm(), I am expecting the data to return with the new created color, but its not returning it. code
Forms\Components\Select::make('color_id')
->label(__('vehicle.attributes.color_id'))
->placeholder(__('vehicle.placeholders.color_id'))
->native(false)
->searchable()
->options(
VehicleInfo\Color::all()->mapWithKeys(fn ($color) => [
$color->id => "<span class='flex items-center gap-x-4'>
<span class='rounded-full w-4 h-4' style='background-color: {$color->color};'></span>
<span>{$color->name}</span>
</span>",
])
)
->reactive()
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\ColorPicker::make('color')
->required(),
])
->createOptionUsing(function (array $data) {
$color = VehicleInfo\Color::create($data);

return $color->id;
})
->allowHtml()
->required(),
Forms\Components\Select::make('color_id')
->label(__('vehicle.attributes.color_id'))
->placeholder(__('vehicle.placeholders.color_id'))
->native(false)
->searchable()
->options(
VehicleInfo\Color::all()->mapWithKeys(fn ($color) => [
$color->id => "<span class='flex items-center gap-x-4'>
<span class='rounded-full w-4 h-4' style='background-color: {$color->color};'></span>
<span>{$color->name}</span>
</span>",
])
)
->reactive()
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\ColorPicker::make('color')
->required(),
])
->createOptionUsing(function (array $data) {
$color = VehicleInfo\Color::create($data);

return $color->id;
})
->allowHtml()
->required(),
2 Replies
Rolland
RollandOP5mo ago
clarifications: the new created color not load in the Select dropdown. bump
arnaudsf
arnaudsf2mo ago
up the only way I found to update the values is to have live() and preload() together. just for record if somebody is looking for it but I wasn't satisfyied by the createOption because I would to have a hintAction. So I changed the createOption for hintAction, do my stuff the $set('my_select', newId) works. My select is relatioship and it works
Want results from more Discord servers?
Add your server