Builder schema not being reactive
Hi, I have this:
Forms\Components\Builder::make('requirements')
->blocks([
Forms\Components\Builder\Block::make('data')
->schema(function (callable $get) {
$type = $get('type');
Log::info($get('type'));
})
->reactive()
And:
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('other')
->options(function (callable $get) {
Log::info($get('type'));
return [$get('type')];
})
->reactive(),
Forms\Components\Select::make('type')
->options(['Option1' => 'Option1'])
->reactive()
->required(),
In the Builder Block::make('data'), the Log is empty, but in the Select::make('other'), the Log is Option1. Why?
How could I get the info from the select inside the Builder schema? Thanks2 Replies
Blocks aren’t reactive. They don’t change their “state” they are only there or not. The form fields inside them are reactive.
What are you trying to accomplish? Maybe there’s another way to accomplish it.
Hi @awcodes ,
Thanks for the clarification, I'm using data objects for each 'type', so in the Builder, depending on the selected type, I need some fields to be filled in or others. Actually, my blocks looks like:
\Components\Builder\Block::make('data')
->label('Features')
->hidden()
->schema(function (callable $get) {
$type = $get('type');
$className = $type ? ucfirst($type) . 'BonusData' : null;
$classPath = "\App\Data\{$className}Data";
return class_exists($classPath) ? self::getReflection($classPath) : [];
})
->reactive()
->columns(3)
This way, as the 'type' select automatically takes the options from the db, simply by adding a new spatie data object we could extend the different fields for each option