Make generic nette redirect after ajax form succeeded
- EmanuelNeu
- Member | 6
Hello world!
I have typical sign up form in signUpControl component with ajax (naja). I want to redirect to Sign:in presenter after the signUpForm is successfully submited. I can redirect with javascript using payload but than flashmessages doesnt work… when i submit this form withot ajax, my loading animation on form doesn't work…
so i want to call typical nette redirect after ajax form was succesfully submited… is it even possible ?
//this will work if the form was not subbmited with ajax
public functon signUpFormSucceeded(Form $form, stdClass $values): void
{
//save user data
$this->getPresenter()->redirect('Sign:in');
}
//this work with ajax but flasshmessages doesnt work...
public functon signUpFormSucceeded(Form $form, stdClass $values): void
{
//save user data
$this->getPresenter()->getPayload()->redirect = $this->presenter->link('Sign:in');
}
//than in js:
naja.addEventListener("success", (event) => {
if (event.detail.payload.hasOwnProperty("redirect")) {
naja.redirectHandler.makeRedirect(event.detail.payload.redirect, true);
}
});
thanks, have a nice day
Neumann.
- EmanuelNeu
- Member | 6
Solution was simple, I don't know why it took me so long to figure it out.
add attribute data-naja-force-redirect
to the form and than call
$this->getPresenter()->redirect('Sign:in');
simple as that.
- m.brecher
- Generous Backer | 864
@EmanuelNeu
instead of data-naja-force-redirect html attribute and this code:
naja.addEventListener("success", (event) => {
if (event.detail.payload.hasOwnProperty("redirect")) {
naja.redirectHandler.makeRedirect(event.detail.payload.redirect, true);
}
});
try this code:
naja.redirectHandler.addEventListener('redirect', (event) => event.detail.setHardRedirect(true))