F
Filament16mo ago
qcol

Confirm modal inside beforeSave hook?

Is it possible to use the confirm modal in the beforeSave hook? I perform a number of actions in beforeSave, some of which require confirmation. Is it possible to confirm some of the actions inside the hook?
Solution:
In this example, I think you have all the information you need to ask this question right in the form, no? If the condition is met, you can show a checkbox below the 2 fields.
Jump to solution
5 Replies
Patrick Boivin
Patrick Boivin16mo ago
I'm not sure beforeSave is the best place for this, but I've never really tried. Just a thought: have you considered using a Wizard with multiple steps, inside of your main action modal? https://filamentphp.com/docs/3.x/actions/modals#using-a-wizard-as-a-modal-form
qcol
qcolOP16mo ago
I don't think Wizard will be useful in my case. Example, I add a delivery of a product to the table " product_deliveries". When saving, in beforesave() I check if the delivery price differs from the price in the product_prices table. If so, I want to ask the user " Should I update the price?". If yes, make a write to the product_prices table. Is there a better place for such an operation than beforesave()?
Solution
Patrick Boivin
Patrick Boivin16mo ago
In this example, I think you have all the information you need to ask this question right in the form, no? If the condition is met, you can show a checkbox below the 2 fields.
Patrick Boivin
Patrick Boivin16mo ago
If this should really be an action with a confirmation modal, you can probably replace the Save button with a custom action, ask to confirm, then call the real save action. Just brainstorming, I'm not sure what is the best approach for you.
qcol
qcolOP16mo ago
You have given me the idea to make the price field as ->live() and after filling it in afterStateUpdated() check if the price differs from the one in the database. If so, unhide hidden checkbox "Update price in product_prices table" . This is the solution, thank you!
Want results from more Discord servers?
Add your server