F
Filament10mo 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(),
]
),
]
)
;
}
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(),
]
),
]
)
;
}
1 Reply
Cow
CowOP10mo ago
I recognize using a full Livewire component when I don't need any reactivity is overkill, so if there's a better way to do this, please point me in the right direction. I really just want to make use of Filament's UI capabilities, to make a searchable dropdown, and I want to keep it consistent with the look-and-feel of the rest of my app, which is using Filament data tables, infolists, etc. But in this particular case, I specifically want a full page load so I don't necessarily need this to be a Livewire form if there's another way to do this Anyone have any insight for me on this question?
Want results from more Discord servers?
Add your server