Dependent select input
I need feature_id dropdown to be populated depending on test_type value
but $get('test_type') is giving me null
->schema([
Forms\Components\Group::make()
->schema([
Forms\Components\Card::make()
->schema([
Card::make()->schema([
TextInput::make('name')->required(),
]),
Select::make('test_type')
->required()
->options([
'auto-test' => 'Auto Test',
'stress-test' => 'Stress Test',
])
->reactive(),
//->afterStateUpdated(function(callable $set){$set('feature_id',null);
// }), Forms\Components\MarkdownEditor::make('notes') ->columnSpan('full'), Forms\Components\Select::make('status') ->default('pending') ->options([ 'pending' => 'Pending', 'processing' => 'Processing', 'completed' => 'Completed', 'failed' => 'Failed', 'has error' => 'Has Error', ]) ->hiddenOn('create'),]) ->columns(2),
// }), Forms\Components\MarkdownEditor::make('notes') ->columnSpan('full'), Forms\Components\Select::make('status') ->default('pending') ->options([ 'pending' => 'Pending', 'processing' => 'Processing', 'completed' => 'Completed', 'failed' => 'Failed', 'has error' => 'Has Error', ]) ->hiddenOn('create'),]) ->columns(2),
6 Replies
The rest of the code
Forms\Components\Section::make('Test features')
->schema(
//static::getFormSchema('features')
[
Forms\Components\Repeater::make('featuresTest')
->relationship()
->schema([
Forms\Components\Select::make('feature_id')
->label('Feature')
->options(function(callable $get){
$type = $get('test_type');
Log::debug($type);
if(!$type){
return ['Please, Enter the type first'];
}
return Feature::where('type',$type);
})
->required()
->reactive()
->columnSpan([
'md' => 7,
]),
Please format your code using three backtick which is written in #✅┊rules , and only show which is related to question..
Your code is a bit of a mess as it's not formatted or complete as VP says.
You will likely need to traverse the structure. i.e. if it's in a group above you do: $get('../test_type')
You can read more here https://filamentphp.com/docs/2.x/forms/fields#using-get-to-access-parent-field-values
Thank you it worked
and I apologize for the mess
Please do this.