Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect JSON Schema for property with choices #7167

Closed
SamMousa opened this issue Oct 17, 2023 · 0 comments
Closed

Incorrect JSON Schema for property with choices #7167

SamMousa opened this issue Oct 17, 2023 · 0 comments
Assignees
Labels
Milestone

Comments

@SamMousa
Copy link
Contributor

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

Bug

What is the current behavior?

When adding a property that uses choices the options are added as possible values to the schema.
However, SurveyJS supports 2 formats for choices:

// Format 1
let choices = [
"a",
"b",
"c"
];
// Format 2
let choices = [
{value: "a", text: "Value A"}
];

When using the second format, the whole object is added as a possible value.

What is the expected behavior?

The value in the value key should be used for the JSON schema.

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

See the demo page i created

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

Tested page URL: https://codesandbox.io/s/json-schema-bug-demo-zdy6gx?file=/src/index.js

Test code

import "survey-core/survey.i18n.js";
import "survey-creator-core/survey-creator-core.i18n.js";
import { Serializer } from "survey-core";
import "survey-core/defaultV2.css";
import "survey-creator-core/survey-creator-core.css";
import "./index.css";

// Add a property to the Survey class
Serializer.addProperty("survey", {
  name: "customSurveyProperty",
  category: "general",
  visibleIndex: 0,
  choices: ["a", "b"]
});
Serializer.addProperty("survey", {
  name: "customSurveyProperty2",
  category: "general",
  visibleIndex: 0,
  choices: [{ text: "a", value: "Value A" }, "b"]
});

const schema = Serializer.generateSchema();

const element = document.getElementById("surveyCreatorContainer");
element.style.whiteSpace = "pre";
element.innerHTML = JSON.stringify(
  {
    customSurveyProperty: schema.properties.customSurveyProperty,
    customSurveyProperty2: schema.properties.customSurveyProperty2
  },
  null,
  2
);

Specify your

N/a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants