F
Filament2mo ago
MZX

Automatically set input field through the input of another field?

I have a form in the package resource. the package has a name, and a price. I have defined enums for the package names. When the user selects the package, i want the price field to be automatically set to the package the user chose. How do I go about it? I did see conditional querying docs but just can't seem to figure it out. Here's the code
Forms\Components\Select::make('name')
->enum(Packages::class)
->options(Packages::class)
->required(),

Forms\Components\TextInput::make('price')
->label('Price')
->numeric()
->disabled()
->prefix('$')
->required(),
Forms\Components\Select::make('name')
->enum(Packages::class)
->options(Packages::class)
->required(),

Forms\Components\TextInput::make('price')
->label('Price')
->numeric()
->disabled()
->prefix('$')
->required(),
4 Replies
Mark Chaney
Mark Chaney2mo ago
You would use afterStateUpdated() with $state and $set(‘price’) to do it. Why are you using an enum for packages? Isn’t the package resource a table of packages with names and associated prices?
MZX
MZX2mo ago
Package is a model. It has 'name' and 'price'. So I made an enum to store the names which are predefined. That's how its done based on one of the filament videos I watched on Laracast. And yes the package resource is a table of package names, and price, (and member id by relationship)
Dennis Koch
Dennis Koch2mo ago
The first part of his answer was still valid.
MZX
MZX2mo ago
yes i am looking into it
Want results from more Discord servers?
Add your server
More Posts