FilamentF
Filament2y ago
Cow

Automatically submit form when Select field changes

I have a very simple Filament form, consisting of a single Select element, which is meant to be a way to switch customers (i.e. tenants) in a multi-tenant application. When the user selects a different value in the select element, I'd like to submit the form (or otherwise perform a full page load of a specific route). The controller action would set the new value for the current customer, and then redirect to the homepage. This feels like really simple, common task, but I'm not finding any way to do it. What am I missing?

Here's the relevant functions in my component:

public function mount(): void
{
   $this->form->fill(['customer_code' => Auth::user()->customer->code]);
}


public function form(Form $form): Form
{
   return $form
      ->schema(
         [
            Select::make('customer_code')
                  ->hiddenLabel()
                  ->required()
                  ->markAsRequired(false)
                  ->selectablePlaceholder(false)
                  ->searchable()
                  ->placeholder('Select')
                  ->searchPrompt('Search')
                  ->live()
                  ->options(
                     [
                        'Active'   => Customer::withoutTrashed()->pluck('code')->toArray(),
                        'Inactive' => Customer::onlyTrashed()->pluck('code')->toArray(),
                     ]
                  ),
         ]
      )
   ;
}
Was this page helpful?