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.13k stars 804 forks source link

Logic for 'Added' Dynamic Matrix Rows #8221

Closed ilaplain15115 closed 5 months ago

ilaplain15115 commented 5 months ago

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

Is it possible to derive logic in a dynamic matrix for a row that has not been added yet?

What is the current behavior?

Currently logic only operates on the initial visible row/observation (1) in the dynamic matrix but not for rows/observations (2+) that are added in the matrix.

What is the expected behavior?

Ideally the logic would apply for the initial row in the dynamic matrix and all subsequent rows that are added.

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

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

Tested page URL:

Test code

{
 "title": "Github3",
 "description": "help matrix logic",
 "logoPosition": "right",
 "pages": [
  {
   "name": "page2",
   "elements": [
    {
     "type": "paneldynamic",
     "name": "question1",
     "title": "Question 1",
     "titleLocation": "top",
     "questionCategory": "surveyquestion",
     "templateElements": [
      {
       "type": "matrixdynamic",
       "name": "observation.question",
       "title": "Observation Question",
       "titleLocation": "hidden",
       "validators": [
        {
         "type": "expression"
        }
       ],
       "questionCategory": "surveyquestion",
       "verticalAlign": "top",
       "columns": [
        {
         "name": "Column 1 initials",
         "title": "Initials",
         "cellType": "text",
         "isRequired": true,
         "validators": [
          {
           "type": "text",
           "text": "Only enter initials",
           "maxLength": 3,
           "allowDigits": false
          }
         ]
        },
        {
         "name": "Column 2 dogs",
         "title": "Likes dogs",
         "cellType": "boolean",
         "isRequired": true
        },
        {
         "name": "Column 3 cats",
         "title": "Likes cats",
         "cellType": "boolean",
         "isRequired": true
        },
        {
         "name": "Column 4 WFH",
         "title": "Works from home",
         "cellType": "boolean",
         "isRequired": true
        }
       ],
       "columnLayout": "vertical",
       "choices": [
        1,
        2,
        3,
        4,
        5
       ],
       "rowCount": 1,
       "addRowLocation": "top",
       "addRowText": "Add TM Observation +"
      },
      {
       "type": "paneldynamic",
       "name": "immediate action",
       "visibleIf": "{question1[0].observation.question[0].Column 2 dogs} = false or {question1[0].observation.question[0].Column 3 cats} = false or {question1[0].observation.question[0].Column 4 WFH} = false",
       "title": "<span style=\"border:1px solid #B2B2B2; background-color:#F1F1F1; padding:20px; font-family: 'lato'; color:#000000; font-size:16px; text-align:center;\"><span class=\"ic ic-exclamation-triangle\" style=\"padding-right:10px;\"></span>Immediate Action Required!</span>",
       "titleLocation": "top",
       "questionCategory": "surveyquestion",
       "templateElements": [
        {
         "type": "checkbox",
         "name": "immediate.actionQ",
         "visibleIf": "{question1[0].observation.question[0].Column 2 dogs} = false or {question1[0].observation.question[0].Column 3 cats} = false or {question1[0].observation.question[0].Column 4 WFH} = false",
         "title": "Complete the following:",
         "isRequired": true,
         "requiredIf": "{question1[0].observation.question[0].Column 2 dogs} = false or {question1[0].observation.question[0].Column 3 cats} = false or {question1[0].observation.question[0].Column 4 WFH} = false",
         "questionCategory": "surveyquestion",
         "choices": [
          "Ask participant why"
         ]
        }
       ],
       "allowAddPanel": false,
       "allowRemovePanel": false,
       "panelCount": 1
      }
     ],
     "allowAddPanel": false,
     "allowRemovePanel": false,
     "panelCount": 1
    }
   ]
  }
 ]
}

Specify your

GIT Hub- EAudit Specs browser: Chrome browser version: 119.0.6045.160 surveyjs platform (angular or react or jquery or knockout or vue): Angular surveyjs version: 1.9.112

JaneSjs commented 5 months ago

Hello @ilaplain15115, From what I gather, you wish to show/hide a question if any column(row) within a Dynamic Matrix receives a specific value.

Survey expressions only allow accessing Dynamic Matrix rows by their index. Unfortunately, it is impossible to refer to 'any' row value. As an option, consider registering a custom function which would check whether any matrix row contains a specified value.

Should you have any further questions, please let me know.

ilaplain15115 commented 3 months ago

Can the custom function rowsWithValue() be used to reference a dynamic matrix?