Question T19288
Visible to All Users

SurveyJs with Svelte latency

created a year ago

Hey, for my project I would like to add surveyJS form on my website coding in svelte.
I succeeded but I have a latency time that I would like to make disappear.

I add the model of form with the JSON and not with the Id so I don't know why this latence before show the form.

I think it's may be the onMouth but i can't add the form without that otherwise it crashes

Here is my code :

JavaScript
import 'survey-knockout/defaultV2.min.css'; import { theme } from '$lib/parts/survey/theme'; import {onMount} from "svelte"; let container: HTMLDivElement; onMount(async () => { const { Survey } = await import('survey-knockout'); const json = { "elements": [...], "showQuestionNumbers": false }; const survey = new Survey(json); survey.applyTheme(theme); survey.showCompleteButton = false; survey.render(container) }); <div bind:this={container}></div>

I didn't find a good tuto to add surveyJS on svelte if someone could help me it will cool :)

Answers approved by surveyjs Support

created a year ago

Hello,

We prepared the example for your https://stackblitz.com/edit/vitejs-vite-qu63f5?file=src%2Flib%2FSurvey.svelte . It uses survey-js-ui package instead of survey-knockout-ui because survey-js-ui is a bit smaller. Could you please check it?

Thank you,
Dmitry
SurveyJS Team

    Show previous comments (2)
    AF AF
    Alister Flandrinck a year ago

      Could you give me a link to the good documentation of the survey? I haven't really found any good ones.

      AF AF
      Alister Flandrinck a year ago

        I found a way to resolve my problem

        I just move the imports in to the onMount like this :

        TypeScript
        onMount(async () => { const { Model } = await import("survey-core"); const { theme } = await import('$lib/parts/survey/theme'); await import("survey-js-ui"); await import("survey-core/defaultV2.min.css"); const { FlatQuestion, FlatSurvey, SurveyHelper, SurveyPDF } = await import('survey-pdf'); const { slk } = await import('survey-core'); const survey = new Model(selectedJson); survey.applyTheme(theme); survey.showCompleteButton = false; survey.data = { client_name: data.client.name, client_address: data.client.address, ...surveyData }; survey.render(container); ... });
        AT AT
        Andrew Telnov a year ago

          Great!
          Thank you for sharing your solution with us.

          Andrew
          SurveyJS Team