surveyjs / surveyjs_react_quickstart

SurveyJS + React Quickstart Template
http://surveyjs.io
140 stars 78 forks source link

Uncaught TypeError: Cannot read property 'getData' of undefined #17

Closed georgejdli closed 4 years ago

georgejdli commented 4 years ago

I complete the first page of the sample survey, hit next, and I see this error in the browser console:

survey.react.js:7625 Uncaught TypeError: Cannot read property 'getData' of undefined
    at JsonObjectProperty.onGetValue (survey.react.js:7625)
    at JsonObjectProperty.getValue (survey.react.js:319)
    at JsonObject.valueToJson (survey.react.js:1304)
    at JsonObject.propertiesToJson (survey.react.js:1296)
    at JsonObject.toJsonObjectCore (survey.react.js:1263)
    at JsonObject.valueToJson (survey.react.js:1310)
    at JsonObject.propertiesToJson (survey.react.js:1296)
    at JsonObject.toJsonObjectCore (survey.react.js:1263)
    at JsonObject.toJsonObject (survey.react.js:1204)
    at PageModel.Base.toJSON (survey.react.js:2113)
    at Function.Helpers.isTwoValueEquals (survey.react.js:1568)
    at ReactSurveyModel.Base.isTwoValueEquals (survey.react.js:2501)
    at ReactSurveyModel.Base.setPropertyValue (survey.react.js:2206)
    at ReactSurveyModel.set [as currentPageValue] (survey.react.js:14502)
    at ReactSurveyModel.set [as currentPage] (survey.react.js:15895)
    at ReactSurveyModel.SurveyModel.doNextPage (survey.react.js:16889)
    at ReactSurveyModel.SurveyModel.doCurrentPageCompleteCore (survey.react.js:16565)
    at ReactSurveyModel.SurveyModel.doCurrentPageComplete (survey.react.js:16556)
    at ReactSurveyModel.SurveyModel.nextPage (survey.react.js:16335)
    at SurveyNavigation.handleNextClick (survey.react.js:19624)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:306)
    at executeDispatch (react-dom.development.js:389)
    at executeDispatchesInOrder (react-dom.development.js:414)
    at executeDispatchesAndRelease (react-dom.development.js:3278)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:3287)
    at forEachAccumulated (react-dom.development.js:3259)
    at runEventsInBatch (react-dom.development.js:3304)
    at runExtractedPluginEventsInBatch (react-dom.development.js:3514)
    at handleTopLevel (react-dom.development.js:3558)
    at batchedEventUpdates$1 (react-dom.development.js:21871)
    at batchedEventUpdates (react-dom.development.js:795)
    at dispatchEventForLegacyPluginEventSystem (react-dom.development.js:3568)
    at attemptToDispatchEvent (react-dom.development.js:4267)
    at dispatchEvent (react-dom.development.js:4189)
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at discreteUpdates$1 (react-dom.development.js:21887)
    at discreteUpdates (react-dom.development.js:806)
    at dispatchDiscreteEvent (react-dom.development.js:4168)

Doesn't seem to be an issue until I try to run React in strict mode and the app panics:

image

georgejdli commented 4 years ago

What my package.json looks like (in case it's a versioning issue):

{
  "name": "surveyjs-example",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "bootstrap": "^4.4.1",
    "jquery": "^3.4.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1",
    "survey-creator": "^1.5.18",
    "survey-pdf": "^1.5.18",
    "survey-react": "^1.5.18",
    "surveyjs-widgets": "^1.5.18"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
georgejdli commented 4 years ago

Ok I think I found the issue:

MyQuestions.js

Survey.Serializer.addClass(
  "myquestion",
  [
    { name: "text" }
  ],
  function() {
    return new MyQuestionModel("");
  },
  "checkboxbase"
);

Using "checkboxbase" seems to be causing the error. After I hit "next" the survey is probably trying to get the choices for the custom question - but there aren't any choices defined in the example. Quick fix was to replace "checkboxbase" with "question"

PR: https://github.com/surveyjs/surveyjs_react_quickstart/pull/18

dmitry-kurmanov commented 4 years ago

Looks ok for me thank you for the contribution