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.22k stars 816 forks source link

Issues when using question valueName/valuePropertyName binding and the Other option when storeOthersAsComment is true #9097

Closed JaneSjs closed 1 day ago

JaneSjs commented 3 days ago

Update

When "valuePropertyName" is set, it doesn't make sense to have the "storeOthersAsComment" as true. It will work as "storeOthersAsComment" is set to false.

T20827 - Disappearing Selected items from Dyanmic Matrix https://surveyjs.answerdesk.io/internal/ticket/details/T20827


Bindings work correctly when a Checkbox doesn't contain the Other item:

{
  "logoPosition": "right",
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "checkbox",
          "name": "question1",
          "valueName": "selectedValues",
          "choices": [
            "Item 1",
            "Item 2",
            "Item 3"
          ],
          "valuePropertyName": "selectedValue"
        },
        {
          "type": "matrixdynamic",
          "name": "question2",
          "valueName": "selectedValues",
          "columns": [
            {
              "name": "Column 1",
              "cellType": "text"
            },
            {
              "name": "Column 2",
              "cellType": "expression",
              "expression": "{row.selectedValue}"
            }
          ],
          "choices": [
            1,
            2,
            3,
            4,
            5
          ],
          "allowAddRows": false,
          "allowRemoveRows": false,
          "rowCount": 0
        }
      ]
    }
  ]
}

image

However, as soon as you enable the Other item, it is no longer possible to select a choice:

{
  "logoPosition": "right",
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "checkbox",
          "name": "question1",
          "valueName": "selectedValues",
          "choices": [
            "Item 1",
            "Item 2",
            "Item 3"
          ],
          "showOtherItem": true,
          "valuePropertyName": "selectedValue"
        },
        {
          "type": "matrixdynamic",
          "name": "question2",
          "valueName": "selectedValues",
          "columns": [
            {
              "name": "Column 1",
              "cellType": "text"
            },
            {
              "name": "Column 2",
              "cellType": "expression",
              "expression": "{row.selectedValue}"
            }
          ],
          "choices": [
            1,
            2,
            3,
            4,
            5
          ],
          "allowAddRows": false,
          "allowRemoveRows": false,
          "rowCount": 0
        }
      ]
    }
  ]
}

https://github.com/user-attachments/assets/ee2cd3b8-2aca-423a-aa15-76f4714b535b

If you remove the expression column which copies a value of a selected checkbox item, another issue occurs: select a value within a row and the first checkbox is unselected. This issue occurs in a user's ticket: T20827 - Disappearing Selected items from Dyanmic Matrix

{
  "logoPosition": "right",
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "checkbox",
          "name": "question1",
          "valueName": "selectedValues",
          "choices": [
            "Item 1",
            "Item 2",
            "Item 3"
          ],
          "showOtherItem": true,
          "valuePropertyName": "selectedValue"
        },
        {
          "type": "matrixdynamic",
          "name": "question2",
          "valueName": "selectedValues",
          "columns": [
            {
              "name": "Column 1",
              "cellType": "text"
            }
          ],
          "choices": [
            1,
            2,
            3,
            4,
            5
          ],
          "allowAddRows": false,
          "allowRemoveRows": false,
          "rowCount": 0
        }
      ]
    }
  ]
}

https://github.com/user-attachments/assets/aac6fb4a-f139-4f47-a1ac-3d32a8681e41

As a w/a, enable the survey's storeOthersAsComment option.

{
  "logoPosition": "right",
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "checkbox",
          "name": "question1",
          "valueName": "selectedValues",
          "choices": [
            "Item 1",
            "Item 2",
            "Item 3"
          ],
          "showOtherItem": true,
          "valuePropertyName": "selectedValue"
        },
        {
          "type": "matrixdynamic",
          "name": "question2",
          "valueName": "selectedValues",
          "columns": [
            {
              "name": "Column 1",
              "cellType": "text"
            }
          ],
          "choices": [
            1,
            2,
            3,
            4,
            5
          ],
          "allowAddRows": false,
          "allowRemoveRows": false,
          "rowCount": 0
        }
      ]
    }
  ],
  "storeOthersAsComment": false
}