Filament: Set Input Value on Select Change

Free Snippet

If you want to set the text input value based on the changed Select option, you can do it with afterStateUpdated() and $set.


How it works

Part of the form() method:

->relationship('product', 'name')
->afterStateUpdated(function (Get $get, Set $set) {
$set('price', Product::find($get('product_id'))->price);

In the afterStateUpdated() method, you get all the form current values in $get(fieldName), and then set the value of any other field with $set(fieldName, newValue).

This snippet comes from a bigger premium example CRM: Customer Management System

A few of our Premium Examples: