How to remove selected item from select input in filament

672 Views Asked by At

I have a one form where I need to take repeater value from user. Inside filament repeater component I have taken one select component. now what I want to do is whenever user tries to add new item remove the previously selected Item from the select component or let's say filter out the select options. here is my code

Repeater::make('meal')
                                        ->relationship('meal')
                                        ->itemLabel(function (array $state): string{
                                            return Section::where('id', $state['section_id'])->get()->pluck('name', 'id')->toArray()[$state['section_id']] ?? '';
                                        })
                                        ->schema([
                                            Hidden::make('order_id')->default(1),
                                            Select::make('section_id')
                                                ->label('Section')
                                                ->searchable()
                                                ->options(function(){
                                                    $data = Section::all()->pluck('name', 'id')->toArray();
                                                    return $data;
                                                })
                                                ->preload()
                                                ->required(),
                                            Select::make('product_id')
                                                ->label('Product')
                                                ->searchable()
                                                ->options(function (Get $get) {
                                                    return Product::query()
                                                        ->where('section_id', $get('section_id'))
                                                        ->where('is_business', false)
                                                        ->where('status', true)
                                                        ->get()
                                                        ->pluck('name', 'id')
                                                        ->toArray();
                                                })
                                                ->preload()
                                                ->required(),
                                        ])
                                        ->columns()
                                        ->minItems(1)
                                        ->maxItems(Section::all()->count())
                                        ->cloneable()
                                        ->columnSpanFull()
                                        ->deleteAction(
                                            fn(Action $action) => $action->requiresConfirmation(),
                                        )
                                        ->addActionLabel('Add New Meal'),

as you can see in the code snippet I have taken one repeater component of filament type of Form\Component

Inside this component I have taken one Select component which is relation to Sections table. so this component will render all the values which are present on section table. now when user tries to enter new meal in that meal block I don't want to display the previously selected value.

I have checked official documentation on filament but nothing helps me. looked for github discussion and also asked question there but not getting this thing happens.

0

There are 0 best solutions below