surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.11k stars 801 forks source link

Bug: navigateToUrl causes popup on 1 page survey and causes data to not be saved on multi page survey #2485

Open Lionqueen94 opened 3 years ago

Lionqueen94 commented 3 years ago

Are you requesting a feature, reporting a bug or asking a question?

Reporting a bug

What is the current behavior?

I have implemented onServerValidateQuestions to validate my survey data and onComplete to save the data and I have added a navigateToUrl. When I submit my survey, I get a popup with: This page is asking you to confirm that you want to leave - data you have entered may not be saved. Only when I click on Leave Page, I get redirected to the navigateToUrl. EDIT: This happens on a 1 page survey. EDIT2: When I remove the navigateToUrl from the json, the data is saved but I still get the popup when I click on a different page to go to.

What is the expected behavior?

I do not want to see the popup, because I'm saving the data so there is no risk of losing data on leaving the page.

Specify your

Lionqueen94 commented 3 years ago

I seem to have an issue with navigateToUrl. When I add it to the json, my survey does not get saved onComplete, it redirects to the navigateToUrl straight away. When I remove it from the json, my survey does get saved and I have to go to a different page myself, without a popup warning that data might not be saved. EDIT: This happens on a multi page survey.

andrewtelnov commented 3 years ago

@Lionqueen94 We do not show this dialog or alert. I believe a browser does it.

Regarding navigateToUrl. We can navigate to url from here and here. The first code calls when you are getting from your server that survey results were saved successfull, the second code when you are just calling the your service code without checking if results were save or not. Here is examples of two approaces. You need the second one, because otherwise your user can leave the page before the code that send the data to your server fully executed.

Thank you, Andrew

Lionqueen94 commented 3 years ago

@andrewtelnov When I use the approach you explained, I keep having the browser popup, but when I call this function:

function redirect() {
  window.onbeforeunload = null;
  window.location.href = url;
}

from the success() in my ajax call I prevent the popup and it works fine.

Another question, is there a way to wait for OnPartialSend to finish before loading the next page?

andrewtelnov commented 3 years ago

@Lionqueen94 We do not wait for onPartialSend event. We are waiting for server validation event only.

PS: Please create a new issue for new question.

Thank you, Andrew

Lionqueen94 commented 3 years ago

@andrewtelnov Ok that makes sense why my code was working when I was saving the data in the onServerValidateQuestions. Thanks for your reply and next time I'll add a new issue/question.