Disable modal submit until criteria met (JS fetch response)
How would I disable an Action’s modal submit button until I have received a response from a fetch request inside an Alpine component in a custom field?
The Pay button is a Filament button which makes a fetch request to a Laravel Controller. If this returns a success I want to enable the submit button.
I don’t know how to communicate from my Alpine / Braintree JS back to the Filament modal.
If that’s not possible then I guess two other options would be to populate a hidden field with a success value and validate it (but again I don’t know how to communicate back to that field) on submitting the modal.
Or, on my fetch request, update a paid status in the database for the payment and check it’s value on submitting. If it’s not paid cancel the submit. I don’t know how to override the submit process and cancel it if paid is false.
Custom field component
Fetch request inside Braintree’s dropin UI - this is just a part of the code....
4 Replies
One other thought - can I remove the submit button? then perform the submission from my Alpine component if payment is successful?
So just to be clear, the various snippets of Javascript you quoted are contained in your testComponent?
Hi Hugh, yes they are. I don’t know how to ‘escape’ them to access Filament for submission etc
Okay, amazing what a new day can bring... I had the concept wrong. I need to think of the component wrapping elements like I have in Vue...
So I can change the state of the DOM pretty easily and add my own submit button.
What I am missing now, is can I remove the Modal’s submit button until
isPaid = true
or remove it entirely and use my own submit?
Solution
For anyone finding this question here’s what I did: