SleepingOwlAdmin icon indicating copy to clipboard operation
SleepingOwlAdmin copied to clipboard

Redirect after saving

Open s6carlo opened this issue 3 years ago • 4 comments

I'm trying to redirect to a specific route after model saving? After model A is saved, I would like to redirect to Model B edit form.

I'm working on the model A method public function save(array $options = array()) is it the right way? I remember that the form buttons could have a a callback, but can't find any reference in the code or documentation

Thanks, CS

s6carlo avatar Sep 21 '20 11:09 s6carlo

FormButton setUrl method is working for SaveAndClose and Save buttons. It does not work for Cancel button, this is because class Cancel has a URL in "initialize" method. I add buttons using this code:


 $form->getButtons()->setButtons([
            'save_and_close' => (new SaveAndClose())->setUrl('myURL')->setText ('Save and go to new URL'),
            'cancel' => (new Cancel())->setUrl('myURL')->setText ('Cancel and go to new URL'),
            'save' => (new Save())
        ]);
 

s6carlo avatar Sep 27 '20 13:09 s6carlo

Solved using a customized button instead of cancel

$button->setName('cancel');
        $button->setText('Cancel');
        $button->setUrl($url);
        $button->setHtmlAttributes($button->getHtmlAttributes() + [
                'class' => 'btn btn-warning',
            ]);
 $form->getButtons()->setButtons([
   $button
        ]);

s6carlo avatar Sep 28 '20 17:09 s6carlo

Is it possible that save and close does not fire "Save" event? The redirect url works, but data are not saved

s6carlo avatar Sep 29 '20 13:09 s6carlo

Using "setUrl" for buttons the default action is not fired, it behaves as a link. Is it a bug ?

s6carlo avatar Sep 29 '20 21:09 s6carlo

https://github.com/LaravelRUS/SleepingOwlAdmin/blob/development/resources/views/default/form/button.blade.php#L6

daaner avatar Feb 14 '23 12:02 daaner