F
Filament15mo ago
Omar

How could I add the options to a Select, when the options are inside the relationship in a json colu

Hello, how could I assign the options depending on the selected form but the options would be inside a json. and tried traversing it in a foreach and allocating the array but it doesn't work.
Forms\Components\Select::make('form_id')
->relationship('form', 'name')
->reactive()
->required(),
Grid::make(1)
->schema([
Repeater::make('metrics')
->id('metrics')
->schema([
Repeater::make('variation_input_targets')
->id('variation_input_targets')
->schema([
Select::make('type_metric')
->required()
->options(function (callable $get) {
$form = ModelsForm::find($get('form_id'));
if($form){
return $form->inputs->pluck('title', 'id');
}
})->reactive(),
]),
]),
Forms\Components\Select::make('form_id')
->relationship('form', 'name')
->reactive()
->required(),
Grid::make(1)
->schema([
Repeater::make('metrics')
->id('metrics')
->schema([
Repeater::make('variation_input_targets')
->id('variation_input_targets')
->schema([
Select::make('type_metric')
->required()
->options(function (callable $get) {
$form = ModelsForm::find($get('form_id'));
if($form){
return $form->inputs->pluck('title', 'id');
}
})->reactive(),
]),
]),
1 Reply
Omar
OmarOP15mo ago
Grid::make(1)
->schema([
Repeater::make('metrics')
->id('metrics')
->schema([
Repeater::make('variation_input_targets')
->id('variation_input_targets')
->schema([
Forms\Components\Select::make('form_id')
->relationship('form', 'name')
->reactive()
->required(),
Select::make('type_metric')
->required()
->options(function (callable $get) {
$form = ModelsForm::find($get('form_id'));
if($form){
$result = array_column($form->inputs, 'title', 'id');
return $result;
}
})->reactive(),
]),
]),
]),
Grid::make(1)
->schema([
Repeater::make('metrics')
->id('metrics')
->schema([
Repeater::make('variation_input_targets')
->id('variation_input_targets')
->schema([
Forms\Components\Select::make('form_id')
->relationship('form', 'name')
->reactive()
->required(),
Select::make('type_metric')
->required()
->options(function (callable $get) {
$form = ModelsForm::find($get('form_id'));
if($form){
$result = array_column($form->inputs, 'title', 'id');
return $result;
}
})->reactive(),
]),
]),
]),
I made a change and there it detects the inputs within the json, but I must have the select of the form inside the repeater, how do I make it detect it outside the repeater?
Want results from more Discord servers?
Add your server