surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.21k stars 814 forks source link

Is it possible to switch columns and rows in a `matrix` question? #1711

Closed csgchristian closed 1 month ago

csgchristian commented 5 years ago

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

Asking a question

I'm aware that matrixdynamic has the property columnLayout, but the same property does not seem to exist on the matrix type of question. I have a question where I would like each column to only support one answer, while currently the matrix question causes each row to only support one answer. Is this possible?

andrewtelnov commented 5 years ago

@csgchristian You may just change the rows and columns. They are the same type. This code should work:

var rows = matrix.rows;
matrix.rows = matrix.columns;
matrix.columns = rows;

Thank you, Andrew SurveyJS Team

csgchristian commented 5 years ago

Are you sure?

I tried that https://plnkr.co/edit/i0MxhgYozKP0kw69ZOM7?p=preview

Not only did the rows and columns remain unchanged, but I was still able to select multiple values in a single column.

EDIT: Rows and Columns do switch, but I can't switch the direction the selection occurs

csgchristian commented 5 years ago

Woops, there was a typo in my plunker code, you are correct that I can flip the rows and columns.

However, the UI still allows me to select more than one value per column! This is not the desired behavior. I also want to flip this.

andrewtelnov commented 5 years ago

@csgchristian Unfortunately, we do not have this functionality since I beleive you are the first who is asking for this. What is the reason of doing this?

Thank you, Andrew

csgchristian commented 5 years ago

We have a paper form, which we would like to convert into an electronic form.

The user expects to see this form online the same way they have seen it before on paper, with vertical column choices.

Functionally it makes no difference, we are just trying to make the transition as smooth as possible.

andrewtelnov commented 5 years ago

@csgchristian I have adeded this into our TODO list. We will implement it if see more requests for this functionality. However, to be honest, I do not think it is a standard behavior for screen UI. People used to have radio groups in horizontal line and not in vertical line. This UI would make sense if there are many columns and just few rows to keep everything on one screen.

Thank you, Andrew

csgchristian commented 5 years ago

To clarify, this form does not use radio buttons, it uses the cells property of the matrix question type.

Even the first example for radiogroup in the Mozilla docs is grouped vertically: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/radiogroup

JaneSjs commented 1 month ago

To ensure a single option per a column use a Multi-Select Matrix. Enable a Radiogroup column, check its `` option and transpose a matrix. Consider the following survey definition:

{
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "matrixdropdown",
          "name": "question1",
          "columns": [
            {
              "name": "Column 1",
              "cellType": "radiogroup",
              "showInMultipleColumns": true
            }
          ],
          "transposeData": true,
          "choices": [
            1,
            2,
            3,
            4,
            5
          ],
          "rows": [
            "Row 1",
            "Row 2",
            "Row 3",
            "Row 4"
          ]
        }
      ]
    }
  ]
}

Now, as rows appear as columns, respondents will be able to select a single option per a column: image