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:Jump to 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.
5 Replies
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-formI 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
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.
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.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!