F
Filament3mo ago
Raven

Reactive Fields

I've got two fields, purchase order and vendor. A purchase order object also has a vendor attached to it. I want it so that if the user selects a purchase order, it automatically selects the vendor and disables the field. If the purchase order gets unselected, the vendor field is cleared and enabled.
Solution:
make the fileds ->live() and put the logic inside the ->disabled(fn(Get $get)=> !$get('purchase_order_id'))
Jump to solution
3 Replies
Raven
RavenOP3mo ago
Select::make('purchase_order_id')->relationship('purchaseOrder',
'reference')->preload()->searchable()->native(false)->label('Purchase Order'),
Select::make('vendor_id')->relationship('vendor',
'name')->preload()->searchable()->native(false)->required()->label('Vendor'),
Select::make('purchase_order_id')->relationship('purchaseOrder',
'reference')->preload()->searchable()->native(false)->label('Purchase Order'),
Select::make('vendor_id')->relationship('vendor',
'name')->preload()->searchable()->native(false)->required()->label('Vendor'),
Solution
Mohamed Ayaou
Mohamed Ayaou3mo ago
make the fileds ->live() and put the logic inside the ->disabled(fn(Get $get)=> !$get('purchase_order_id'))
Mohamed Ayaou
Mohamed Ayaou3mo ago
you may implement more logic with ->afterStateUpdated()

Did you find this page helpful?