UnderOath777
Dynamic Form Component
Thank you! This is what I managed to get working.
public static function form(Form $form): Form
{
$serviceTypeOption = ServiceTypeManager::options();
return $form
->schema([
TextInput::make('name'),
Select::make('service_type')
->live()
->options($serviceTypeOption)
->afterStateUpdated(function (Select $component) {
$component->getContainer()
->getComponent('settings')
->getChildComponentContainer()
->fill();
}),
Group::make(static function (Get $get) {
$value = $get('service_type');
if ($value) {
return ServiceTypeManager::make($value)->formComponents();
}
return [];
})->statePath('settings')
->key('settings')
]);
}
public static function form(Form $form): Form
{
$serviceTypeOption = ServiceTypeManager::options();
return $form
->schema([
TextInput::make('name'),
Select::make('service_type')
->live()
->options($serviceTypeOption)
->afterStateUpdated(function (Select $component) {
$component->getContainer()
->getComponent('settings')
->getChildComponentContainer()
->fill();
}),
Group::make(static function (Get $get) {
$value = $get('service_type');
if ($value) {
return ServiceTypeManager::make($value)->formComponents();
}
return [];
})->statePath('settings')
->key('settings')
]);
}
4 replies