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
898 stars 373 forks source link

A custom column property value doesn't appear for the 'matrixdropdowncolumn' type #5040

Closed JaneSjs closed 9 months ago

JaneSjs commented 9 months ago

User Issue: T16184 - Custom property for Dynamic Matrix Column https://surveyjs.answerdesk.io/internal/ticket/details/T16184


View Demo If you register a custom property for a matrixdropdowncolumn, question, and dropdown, the custom property value doesn't appear for a matrix column. image image

import { SurveyQuestionEditorDefinition } from "survey-creator-core";
import { surveyJson } from "./surveyJSON";

const customProp = {
  name: "customProp",
  category: "general",
};
Serializer.addProperty("matrixdropdowncolumn", customProp);
Serializer.addProperty("question", customProp);
Serializer.addProperty("dropdown", customProp);

SurveyQuestionEditorDefinition.definition[
  "matrixdropdowncolumn@default"
].properties.push(customProp);

Expected behavior: the custom property for matrix columns display values defined within a survey JSON.

andrewtelnov commented 9 months ago

Here is the correct code and the working example:

const customProp = {
  name: "customProp",
  category: "general"
};

const columnCustomProp = {
  name: customProp.name,
  category: customProp.category,
  onGetValue: function (obj) {
    return obj.templateQuestion[customProp.name];
  },
  onSetValue: function (obj, value) {
    obj.templateQuestion[customProp.name] = value;
  }
}

Serializer.addProperty("question", customProp);
Serializer.addProperty("matrixdropdowncolumn", columnCustomProp);

SurveyQuestionEditorDefinition.definition[
  "matrixdropdowncolumn@default"
].properties.push(customProp.name);