surveyjs / survey-creator

Scalable open-source survey software to generate dynamic JSON-driven forms within your JavaScript application. The form builder features a drag-and-drop UI, CSS Theme Editor, and GUI for conditional logic and form branching.
https://surveyjs.io/open-source
Other
896 stars 370 forks source link

V2 Serializer is undefined from survey-react-ui #2670

Open Russelldan554 opened 2 years ago

Russelldan554 commented 2 years ago

Are you requesting a feature, reporting a bug or ask a question?

I have found a bug while using Creator V2 where the Serializer property is not on the Survey component. I am trying to add code from the minimalistic example into the V2 creator found here(https://surveyjs.io/Examples/Survey-Creator?id=singlepage&platform=ReactjsV2&theme=modern#content-js).

I also noticed in the CreatorV2 examples if you select ReactV2 and edit in Codesandbox the page above is failing. image

What is the current behavior?

TypeError: Cannot read properties of undefined (reading 'findProperty')
>  99 | Survey.Serializer.findProperty("itemvalue", "visibleIf").visible = false;
  100 | Survey.Serializer.findProperty("itemvalue", "enableIf").visible = false;
  101 | Survey.Serializer.findProperty("itemvalue", "text").visible = false;

What is the expected behavior?

Hide item value properties

How would you reproduce the current behavior (if this is a bug)?

Try to access Serializer from the survey-react-ui library

Provide the test code and the tested page URL (if applicable)

import React from "react";
import * as SurveyCreator from "survey-creator-react";
import * as Survey from "survey-react-ui";

const options = {
  showJSONEditorTab: false,
  showLogicTab: false,
};

const creator = new SurveyCreator.SurveyCreator(options);

// Hide some properties of the itemvalue object
// Design itemvalue[] property editor
// Hide visbileIf, enableIf and text properties
Survey.Serializer.findProperty("itemvalue", "visibleIf").visible = false;
Survey.Serializer.findProperty("itemvalue", "enableIf").visible = false;
Survey.Serializer.findProperty("itemvalue", "text").visible = false;

export default function SurveyJS() {
  return (
    <React.Fragment>
      <React.StrictMode>
        <SurveyCreator.SurveyCreatorComponent creator={creator} />
      </React.StrictMode>
    </React.Fragment>
  );
}

Specify your

tsv2013 commented 2 years ago

Thank you for the report. Yes we aware that some codesandbox examples are not set up properly for Creator V2, The Serializer class shoudn't be accessible from survey-react-ui module. It belongs the survey-core module:

import * as Survey from "survey-core";
Survey.Serializer.findProperty("itemvalue", "visibleIf").visible = false;
tsv2013 commented 2 years ago

We'll fix the codesandbox examples.

Russelldan554 commented 2 years ago

Oh Ok I will use the core module thanks!

tsv2013 commented 2 years ago

I've fixed the example code, but it will be availalbe with the 1.9.14 release planned next tuesday