Having trouble figuring out best way to add a button to a modal, which triggers custom JS
I have some custom JS that prints to a Zebra label printer. My goal is to have an Action on the Edit Resource page (done) that opens a modal. Within the modal I need to show a brief form that isn't related to a Model, it's just a custom form with a dropdown and a "Print" button.
What I'm struggling with is: what is the right way to do this? However, I'm not even sure if I should be looking for a FilamentPHP right way, or a Livewire right way, or an AlpineJS right way, etc. In other words, it's easy enough to include the JS, add a button that triggers it and prints the label - but it doesn't seem like I'm building it using the tools provided and that's what I'd like to do.
Is this something that I should be looking to build using the FilamentPHP Api or not?
7 Replies
Is the sdk for the printer js based? If so then you should be focused on an alpine integration.
It is JS based
Doesn’t sound like you even need filament for this.
Ok, thanks; I'll dig into Alpine. I was just reading through https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component and wondering if I need a livewire component that has a Filament form, which is displayed in a modal. I'm probably way over-complicating it as a result of not understanding everything I have at my disposal
You could use the filament action and use ->form() on the action to not need a separate livewire component. Then in the ->action() you can dispatch an event that calls the sdks methods.
Would need listeners on the sdk js side though.
Long story short it’s all still js so don’t get caught up on the “Filament way” or not.
This helps a lot - thank you!
Use filament / laravel where it makes sense.