I have made the setting showPreviewBeforeComplete: showAnsweredQuestions.
Now I have two problems:
Problem No 1:
When I have 2 questions on two different pages and I klick 'edit' on the preview page on question 1, surveyjs shows me question 2 of the second page instead question 1 on the first page.
Problem No 2:
When the onCurrentPageChanging event is fired I am saving the current data to the database.
So I can save the data during page changes and stay on the page if there is an error on the server while saving the data.
When I klick 'edit' on the preview page on a questions it returns the the survey pages and calls the onCurrentPageChanging event too.
So the data is saved again, if i return to a page.
How can I find out when handling the onCurrentPageChanging event if the user returns in this way to a page (that is already saved), so I prevent saving it again.
Ok, think I found the reason for problem 1.
During onCurrentPageChanging I set nextPageIsProcessing = true
and only if the data saving on the server was successful I call survey.nextPage() to move to the next page.
As described in problem 2 when clicking on the edit button of question 1, question 2 on the next page is displayed.
When clicking on the edit button in the preview page surveyjs would correctly navigate to page 1.
The problem is, that during this process onCurrentPageChanging is executed.
When this happens data is saved to the server and after the successful saving survey.nextPage() is called by me.
And because surveyjs was correctly on page 1 this call of survey.nextPage() is the reason why it results in displaying page 2 instead of page 1.
So if you can tell me how I can detect in onCurrentPageChanging that the page is openend from the preview page I can not call the unnecessary saving that moves to the next page when saving was successfull.
This is my current code:
async function savePartial(sender, options) { if(options.isPrevPage || nextPageIsProcessed) { return; } options.allow = false; survey.navigationBar.getActionById("sv-nav-next").enabled = false; nextPageIsProcessed = true; //Clear actions for notifier survey.notifier.actionBar.actions = []; returnedFormSubmissionId = await saveSurveyData(sender, options, false); if (returnedFormSubmissionId === ERROR) { console.log("returnedFormSubmissionId is null"); survey.notify(DataSavingErrorMsg, "error"); } else { console.log("returnedFormSubmissionId is not null"); if (formSubmissionId == null) { formSubmissionId = returnedFormSubmissionId; } console.log("nextPage"); survey.nextPage(); } console.log("am ende"); survey.navigationBar.getActionById("sv-nav-next").enabled = true; nextPageIsProcessed = false; } survey.onCurrentPageChanging.add((sender, options) => { console.log("onCurrentPageChanging"); survey.notify(SavingMsg, "info"); savePartial(sender, options); });
Hello Peter,
I think we need a better API here. Probably do not call this event twice on changing from preview to edit or add a new property to the options. I will think about it.
Here is the dirty work-around:
survey.onCurrentPageChanging.add((sender, options) => { if(!options.oldCurrentPage || options.oldCurrentPage.name === "all") return; console.log("onCurrentPageChanging"); survey.notify(SavingMsg, "info"); savePartial(sender, options); });
Thank you,
Andrew
SurveyJS Team
FYI: Here is the related issue on GitHub.
Thank you,
Andrew
SurveyJS Team
FYI: I have fixed the issue by this PR. We will have a new attribute in options:
isAfterPreview: boolean
. We may change the attribute name before the release.Thank you,
Andrew
SurveyJS Team