Is there a way in Filament to calculate a field on the client side without Livewire? AlpineJS?
I have a form as defined here:
The problem with this calculated field
available_quantity
is that the calculation requires the adjustment
field to be live which causes debounce issues with the client as seen in the attached GIF. When updating the field that has already sent an ajax request to the server, the client side updates but then reverts if another client side update occurred before getting the ajax response.
In a non-Filament app I'd solve this by just doing the calculation through AlpineJS and never requiring a live field. However, I'm not sure how I'd do this in the context of a Filament app.
Solution:Jump to solution
Actually what you want is to use AlpineJS to do it for you.. using extraAttributes I suspect? Roughly like:
```php
Forms\Components\TextInput::make('adjustment')
->helperText('Increase or decrease available quantity')...
6 Replies
Solution
Actually what you want is to use AlpineJS to do it for you.. using extraAttributes I suspect? Roughly like:
exactly what I'm looking for thanks 😄
I'll go add this and report back.
So, It's not working but I believe because this is adding the
x-data
to the trigger button and not the form itself.

Not sure how to overcome that
I tried using
extraModalWindowAttributes
but that doesn't add anything.
I tested extraModalWindowAttributes
with a test attribute and it works so it appears that because there is already an x-data
attribute on the modal, it doesn't add the custom one.
Solved. I put the extra attributes on a form group component:
Forms\Components\Group::make()->extraAttributes()->schema([])
Everything is working speedily! 😄 thanks.Fantastic work!