Redirect or refresh after BetterButtonNestedForm submit
adrian-stein opened this issue · comments
This sort of relates to [https://github.com//issues/126] but could also be classed as a new issue. I can close and comment on the other one if that is the case.
When using BetterButtonNestedForm
on an order object I am setting the order as archived and entering an invoice number, I then save the object that I was viewing from the custom action. This saves the object but gives errors. In updateBetterButtonsActions
I have a check to only show the archive button if the order is not archived and when I click the action to archive it I get the error "Action archive doesn't exist or is not a BetterButtonNestedForm
". I assume this is because the button is not included as the order is now archived. I guess I can get around this by making sure to add a button that has the same type and action name but does nothing if the order is already archived, but this doesn't sounds like a great way or doing it.
Ideally it should be able to do one of 2 things:
- On the saving of the
BetterButtonNestedForm
it updates the entire page so the archive button is not rendered on the page ( will have to happen before I close the dialog) - On save it redirects to the same page or another page. I can do a
Controller::curr()->redirect('admin/orders');
from the custom action but this redirects the iframe in the ssdialog and not the parent page. I dont mind if it redirects back to the list page and shows all orders or the existing page but with updated information.
Is there already a work around to get past this issue? As updating the record you are viewing with a BetterButtonNestedForm
seems like a fairly common task, but I note your example doesnt save data just send a message.
Cheers Adrain
+1
Needed this for a project so hacked something together. It’s horrible (tight deadline, what can I say?) but it works: https://gist.github.com/kinglozzer/076668800c9e4b35ec40d92b3e3f6a00
Just use BetterButtonBetterNestedForm::create()
instead of BetterButtonNestedForm::create()
. Make sure your actions return a string with a success message, it’ll get added to the parent form (the one outside the dialog) and perform a hard refresh