Radio/Select

I have one problem, not sure how to solve it. I have a Radio to select between 2 options: First is to pickup, and the second is for the delivery. What I want is to, if you click on "delivery" to open a select option to choose which carrier you want as a delivery. Here's how it looks like :
Grid::make(1)
->disabled(function () {
return $this->isDisabled;
})
->columnSpan(1)
->schema([
Select::make('customer_id')->relationship('customer', 'name')->required(),
Radio::make('delivery_type')
->options([
'delivery' => 'Delivery',
'local_pickup' => 'Local Pickup',
])
->required(),
Select::make('delivery_id')
->when('delivery_type', 'delivery', function ($field) {
return $field->relationship('delivery', 'to_organisation')->required();
}),
Select::make('status')->options(config('configurator.order_status'))->required(),
]),
])
Grid::make(1)
->disabled(function () {
return $this->isDisabled;
})
->columnSpan(1)
->schema([
Select::make('customer_id')->relationship('customer', 'name')->required(),
Radio::make('delivery_type')
->options([
'delivery' => 'Delivery',
'local_pickup' => 'Local Pickup',
])
->required(),
Select::make('delivery_id')
->when('delivery_type', 'delivery', function ($field) {
return $field->relationship('delivery', 'to_organisation')->required();
}),
Select::make('status')->options(config('configurator.order_status'))->required(),
]),
])

And this is the current outcome in the picture attached> Any kind of help would be awesome! Many thanks!
3 Replies
Dennis Koch
Dennis Koch2y ago
Please format your code according to #✅┊rules Check the docs for "dependant fields". There is even an example
LeandroFerreira
Radio::make('delivery_type')
->options([
'delivery' => 'Delivery',
'local_pickup' => 'Local Pickup',
])
->required()
->reactive(),
Select::make('delivery_id')
->visible(fn ($get): bool => $get('delivery_type') === 'delivery')
Radio::make('delivery_type')
->options([
'delivery' => 'Delivery',
'local_pickup' => 'Local Pickup',
])
->required()
->reactive(),
Select::make('delivery_id')
->visible(fn ($get): bool => $get('delivery_type') === 'delivery')
dusan8061
dusan8061OP2y ago
Yes, that's it. Many, many thanks!
Want results from more Discord servers?
Add your server