Question T2768
Visible to All Users

Survey.Model is not a constructor

created 6 years ago

I am using vanilla Meteor (using Blaze, not React, Angular or Vue) and jQuery. I have Survey Creator working just fine using code that is similar to what you see below. However, I'm building a page to display the survey, and survey-jquery gives me the error "Survey.Model is not a constructor". My code is fairly simple:

JavaScript
import { Template } from "meteor/templating" import $ from 'jquery' import { Survey, Model } from 'survey-jquery' import './survey-form.html' Template.surveyForm.onRendered(function() { const template = Template.instance() const surveyData = { "pages": [ { "name": "page1", "elements": [ { "type": "text", "name": "question1" } ] } ] } let surveyInstance = new Survey.Model(surveyData) template.$("#surveyFormContainer").Survey({ model: surveyInstance, onComplete: function todo () {} }) })

Any help would be appreciated. Because this is Meteor, I cannot easily send you a Plunker to demonstrate the problem.

Comments (3)

    Hello,

    I've not tested it (right now) but I think it should look lile

    JavaScript
    import { Model } from 'survey-jquery'

    or

    JavaScript
    import * as Survey from 'survey-jquery'

    Thanks, Serge
    SurveyJS Team

      My original import:

      JavaScript
      import { Survey, Model } from 'survey-jquery'

      Suggestion #1:

      JavaScript
      import { Model } from 'survey-jquery'

      Throws the error: "Survey is not defined"

      Suggestion #2:

      JavaScript
      import * as Survey from 'survey-jquery'

      Yay! It works! Thank you.

      Paul

      On 10/9/2019 11:14:50 AM, Support Support <

        Hello,

        Thats good! Please feel free to contact us in case of any further questions

        Thanks, Alex
        SurveyJS Team