We would like to customize the structure of the matrix type of question. Currently it is :
We have three different flavors of Text (long text, short text and numeric) and the others are just re-names of the ones that currently exist. We think that Comment could match to long text, Text could be used as short text but need to add the Numeric that is just a second Text field with inpiut type "numeric". Can you suggest how we can achieve this?
modifying matrix question structure
Answers
Hello support,
I am trying to load custom, pre-configurated questions into the list of sub-question types within a matrix multiple choice question:
As an example, I tried to use the code below to create a yes/no preset for radiogroup with the options yes and no already preconfigured:
JavaScriptSurvey.matrixDropdownColumnTypes.si_no = {
properties: ["hasOther", "otherText", "choicesOrder", "colCount"],
tabs: [
{ name: "choices", index: 10 },
{ name: "choicesByUrl", index: 11 },
{ name: "visibleIf", index: 12 },
{ name: "enableIf", index: 20 }
]
};
survey.text = JSON.stringify({
questions: [
{
columns: [
{
name: "si_no",
"cellType": "checkbox",
title: "Sí/No",
json: {
"categoria": "Descarte",
"choices": [
"Sí",
"No"
]
}
}
]
}
]
});
The problem is I get this error:
I also noticed we're missing the option to choose 'multiple text' from that same list. How would we go about adding it?
Any help would be appreciated.
Thanks
Luis
Hello, Luis
I've created a working sample for you, based on custom widget - https://plnkr.co/edit/TJ4cTS?p=preview
Does if fit your needs?
Thanks, Serge
SurveyJS Team
Hello Serge,
Yes, that example works! and thank you very much for the example. But I have other issue when I´m adding multipletext question into Matrix (multiple choice). This is my code:
JavaScriptvar widget = {
name: 'grupo_de_campos',
title: "Grupo de Campos",
iconName: "icon-multipletext",
widgetIsLoaded: function() {
return true;
},
isFit: function(question) {
//question.items = [{"name": "text1"},{"name": "text2"}];
return question.getType() === "grupo_de_campos";
},
isDefaultRender: true
}
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
Survey.JsonObject.metaData.addClass(
"grupo_de_campos",
[
{ name: "choicesByUrl", visible: false },
{ name: "hasOther", visible: false },
{ name: "otherText", visible: false },
{ name: "storeOthersAsComment", visible: false },
{ name: "choices", visible: false }
],
null,
"multipletext"
);
//add file type into matrix columns (run-time)
Survey.matrixDropdownColumnTypes.grupo_de_campos = {
properties: ["name", "categoria", "colCount", "items"]
};
SurveyEditor
.SurveyQuestionEditorDefinition
.definition["matrixdropdowncolumn@grupo_de_campos"] = {
properties: ["name", "categoria", "colCount"],
tabs: [{ name: "items", index: 10 }]
}
This is the view:
And when i click Ok, this is the error message that the console gives me:
Also I have another cuestion. How can i delete or hide this default questions in the matrix:
And how Can I change the name of the question, for example in the code above is called "grupo_de_campos" but i want the display in the matrix show like this "Grupo de Campos" using spaces and first letter uppercase. I saw that the string that I'm writing here
Is the string that will be display int the select area, but obviously i can´t write using spaces.
Thanks you.
Luis
It's a bug in the text item title inplace editor. I've fixed it via the https://github.com/surveyjs/editor/commit/d31b77ac269445fc38fbd5ad886a4f9041396b45 commit.
Fix will be available in the nearest update.
Thanks, Serge
SurveyJS Team
Hello,
Here is the example that removes unneeded cell types and adds a number cell type: https://plnkr.co/edit/SQI7busInZdEFtkAbfj0?p=preview
Here is the code:
JavaScript//delete all cell types except text and comment
for(var key in Survey.matrixDropdownColumnTypes) {
if(key == "text" || key == "comment") continue;
delete Survey.matrixDropdownColumnTypes[key];
}
//Add new class - numeric
Survey.JsonObject.metaData.addClass("numeric", [], function() { var q = new Survey.QuestionText(""); q.inputType = "number"; return q; }, "text");
Survey.matrixDropdownColumnTypes.numeric = {properties: ["placeHolder"] };
Right now, there is no way to change the cell type text in the dropdown. I'm thinking about getting names from questions titles in the toolbox. For example, by default text has title "Single input". You may change it, but it will be change in toolbox and in cell types dropdown. Will it work for you?
Thank you,
Andrew
SurveyJS Team
Hello,
As far as I understand this functionality is available since 1.0.16, released on April, 2nd.
Thanks Serge,
SurveyJS Team
in a related question,
can we add "multiple text" questions to a matrix question type? How? It doesn't appear in the choces.
Thanks again for all your help!
Hello,
Here is the demo of adding a file type question into matrix: https://surveyjs.io/Examples/Builder/?id=matrixcustomcelltypes
Thank you,
Andrew
SurveyJS Team