F
Filament17mo ago
KeyMe

CreateOptionForm in Repeater with dependent select component

I have a Repeater with dependent addon_name select field that ties to the addon_type field. Now I want users to be able to add new add-on name options to the list, like others, the problem is I didn't define the relationship() for the addon_name from the get-go. Bcs as you know I use the customization technique for the dependent name options. How do I go about this?
Select::make('addon_id')->label('Add-on Name')
->options(function (callable $get) {
$type = $get('type');

if (!$type) {
return Addon::pluck('name', 'id');
}
return Addon::where('type', $type)->pluck('name', 'id');
})
->searchable()
->reactive()
->createOptionForm([
Select::make('type')->label('Add-on Type')
->options(Addon::pluck('type', 'type'))
->placeholder('Select type')
->required(),
TextInput::make('name')->required()
])
->required(),
Select::make('addon_id')->label('Add-on Name')
->options(function (callable $get) {
$type = $get('type');

if (!$type) {
return Addon::pluck('name', 'id');
}
return Addon::where('type', $type)->pluck('name', 'id');
})
->searchable()
->reactive()
->createOptionForm([
Select::make('type')->label('Add-on Type')
->options(Addon::pluck('type', 'type'))
->placeholder('Select type')
->required(),
TextInput::make('name')->required()
])
->required(),
Solution:
```php ->createOptionForm([ Select::make('type')->label('Add-on Type') ->options(Addon::pluck('type', 'type')) ->required(),...
Jump to solution
4 Replies
Patrick Boivin
Patrick Boivin17mo ago
@keyme0209 Can you share the Repeater code and a quick screenshot? Not sure I'm getting the full picture yet... I think you're missing a createOptionUsing()
KeyMe
KeyMeOP17mo ago
Repeater::make('AddonOrders')->label('Cameras & Accessories')
->relationship()
->schema([
Select::make('type')->label('Add-on Type (Optional)')
->options(Addon::pluck('type', 'type'))
->reactive()

// addon id/name options are dependent on the type selected above
Select::make('addon_id')->label('Add-on Name')
->options(function (callable $get) {
$type = $get('type');

if (!$type) {
return Addon::pluck('name', 'id');
}
return Addon::where('type', $type)->pluck('name', 'id');
})
->reactive()
->createOptionForm([
Select::make('type')->label('Add-on Type')
->options(Addon::pluck('type', 'type'))
->required(),
TextInput::make('name')->required()
])
->required(),
Repeater::make('AddonOrders')->label('Cameras & Accessories')
->relationship()
->schema([
Select::make('type')->label('Add-on Type (Optional)')
->options(Addon::pluck('type', 'type'))
->reactive()

// addon id/name options are dependent on the type selected above
Select::make('addon_id')->label('Add-on Name')
->options(function (callable $get) {
$type = $get('type');

if (!$type) {
return Addon::pluck('name', 'id');
}
return Addon::where('type', $type)->pluck('name', 'id');
})
->reactive()
->createOptionForm([
Select::make('type')->label('Add-on Type')
->options(Addon::pluck('type', 'type'))
->required(),
TextInput::make('name')->required()
])
->required(),
@pboivin here
Solution
LeandroFerreira
LeandroFerreira17mo ago
->createOptionForm([
Select::make('type')->label('Add-on Type')
->options(Addon::pluck('type', 'type'))
->required(),
TextInput::make('name')->required()
])
->createOptionUsing(function (array $data) {
$addon = Addon::create($data);
return $addon->id;
})
->createOptionForm([
Select::make('type')->label('Add-on Type')
->options(Addon::pluck('type', 'type'))
->required(),
TextInput::make('name')->required()
])
->createOptionUsing(function (array $data) {
$addon = Addon::create($data);
return $addon->id;
})
?
KeyMe
KeyMeOP17mo ago
thank you that worked, was gonna say the new addon name is inserted in database but for some reason when i submitted the form, the addon type was included in the addon name options as well haha. we returned the wrong thing many thanks mr leandro~!
Want results from more Discord servers?
Add your server