Forms\Components\Tabs\Tab::make('Input')
->statePath('input')
->schema([
Forms\Components\Select::make('type')
->options(InputTypes::listOptions())
->required()
->live()
->afterStateUpdated(function ($state) {
if ($state) {
$types = InputTypes::list();
$type_class = $types[$state];
self::$input_type_class = $type_class;
}
}),
... self::getInputSettingsFieldsets(), // instead of the code above
]),
public static function getInputSettingsFieldsets(): array
{
$forms = [];
$input_types = InputTypes::list();
foreach ($input_types as $id => $input_type_class) {
$forms[] = Forms\Components\Fieldset::make('input_settings')
->label(__('Settings'))
->statePath('settings')
->visible(function (Get $get) use ($id) {
if ($get('type') == $id) {
return true;
} else {
return false;
}
})
->schema(function () use ($input_type_class) {
return $input_type_class::settingsForm() ?? [];
});
}
return $forms;
}