Question T18251
Visible to All Users

Add navigation item to survey preview

created 7 months ago (modified 7 months ago)

Hi,
I want to add 'Save as PDF' button to my survey preview page, but when I use

Code
survey.addNavigationItem({ id: 'survey_save_as_file', title: 'Save as PDF', action: async () => { await saveSurveyToPdf('surveyResult.pdf', survey, JSON.parse(schema)); }});

I don't have this navigation button on my preview page.

Answers approved by surveyjs Support

created 7 months ago

Hello,
Please subscribe to the creator.onSurveyInstanceCreated event, obtain a previewed survey and register a required navigation item.

JavaScript
creator.onSurveyInstanceCreated.add((sender, options) => { if(options.area === "preview-tab") { const survey = options.survey; survey.addNavigationItem({ id: 'survey_save_as_file', title: 'Save as PDF', action: async () => { await saveSurveyToPdf('surveyResult.pdf', survey, JSON.parse(schema)); }}); } })

Also, if you wish to add a Save PDF button to a survey preview tab, you may consider adding a custom toolbar action to a creator toolbar. A demo is available at Toolbar customization.

Let me know if you have further questions.